maxatwork / form2js

Javascript library for collecting form data
http://maxatwork.github.com/form2js/
MIT License
640 stars 137 forks source link

checkboxes should return JSON true/false #15

Open boxxxie opened 13 years ago

boxxxie commented 13 years ago

in the case of false (unchecked) it doesn't need to return anything as if(variable) will have the same behavior with null as with false. the 'false' case works. the 'true' case doesn't work.

will return

"exemption": {
    "enabled": "true"
},

where as it should return

"exemption": {
    "enabled": true
},
boxxxie commented 13 years ago

code fix: case 'checkbox': if (fieldNode.checked){ if(fieldNode.value === "true"){return true;} return fieldNode.value; } break;

in function: function getFieldValue(fieldNode)

boxxxie commented 13 years ago

sorry, i'm still a git noob, so i didn't fork / pull-req

maxatwork commented 12 years ago

Fixed with 985a3f3214303e2c51d032590ec0b9fb15e51b63

boxxxie commented 12 years ago

I think that your code would be greatly simplified if it used jquery... pulling all of the objects with a name field is 1 line of code. some of the code i wrote for my js2form implementation could be used to simplify transforming field names into objects and putting values in them.

it's not a big deal for me, though, because i'm using templates for this type of stuff now.