29 Mar 2014 10:46 AM #1
Checkbox value in form submitted as true/false instead of 1/0
I have a form that includes a checkbox field and on form submit, I want the checkbox value as 1 or 0.
The jsonSubmit is enabled for the form.
The checkbox value is submitted as true or false instead of 1 or 0.
I have specified the inputValue and uncheckedValue for the form.
The value is submitted as 1 or 0 when jsonSubmit is disabled.
How to solve this problem.
2 Apr 2014 8:37 AM #2
Which Ext version are you using?
Can you share your code?
This seems to work fine: https://fiddle.sencha.com/#fiddle/4niIsrael Roldàn | Software Engineer (Frameworks)
2 Apr 2014 8:23 PM #3
I m using v4.2.1 . I get 1 or 0 with form.getValues().
But on form.Submit() the value submitted is true or false.
Right now I have overriden the checkbox's getValue() method to return the value as 1 or 0. Is it the right way to fix it or is there any config that I can set for the checkbox
7 Apr 2014 12:17 PM #4
The inputValue and uncheckedValue configs only affect the submitted value if jsonSubmit is false, as you've seen. When jsonSubmit is enabled, it uses the getModelData() method of the field to get the data for submission. Normally I believe getModelData() calls getValue() to get the value, so I'm surprised overriding getValue() didn't do what you want. You can try overriding getModelData()directly, but failing that I would set a breakpoint in Ext.form.Basic.getValues() and then step through with a debugger to see where the value is coming from.