Incoming data quoted "false" treated as true
rhinmass opened this issue · 0 comments
rhinmass commented
If the data has quotes around the "false" , it is parsed as true. My understanding is that quotes around booleans is valid in json.
When alpaca is reading the data, it should know it's handling a boolean field and should interpret "false" as false. It seems looking in the source , this is the intent, as seen here in the function ensureProperType
.
else if (type === "boolean")
{
if (v === "" || v.toLowerCase() === "false")
{
v = false;
}
else
{
v = true;
}
}
But this code doesn't seem to be getting called.
Here is a snippet to illustrate this case
$(document).ready(function() {
$("#form").alpaca({
"data": {
"name": "Diego Maradona",
"feedback": "Very impressive.",
"ranking": "excellent",
"recommend" : "false",
},
"schema": {
"title":"User Feedback",
"description":"What do you think about Alpaca?",
"type":"object",
"properties": {
"name": {
"type":"string",
"title":"Name"
},
"feedback": {
"type":"string",
"title":"Feedback"
},
"ranking": {
"type":"string",
"title":"Ranking",
"enum":['excellent','ok','so so']
},
"recommend" : {
"type" : "boolean",
"title" : "Would you recommend us to a friend?"
},
}
},
});
});