form2js icon indicating copy to clipboard operation
form2js copied to clipboard

checkboxes should return JSON true/false

Open boxxxie opened this issue 13 years ago • 4 comments

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 avatar Oct 11 '11 15:10 boxxxie

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

in function: function getFieldValue(fieldNode)

boxxxie avatar Oct 11 '11 15:10 boxxxie

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

boxxxie avatar Oct 11 '11 15:10 boxxxie

Fixed with 985a3f3214303e2c51d032590ec0b9fb15e51b63

maxatwork avatar Nov 13 '11 10:11 maxatwork

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.

boxxxie avatar Nov 15 '11 18:11 boxxxie