1. #1
    Sencha User
    Join Date
    Jul 2013
    Posts
    11
    Vote Rating
    0
    Thinker Bug is on a distinguished road

      0  

    Default Checkbox value in form submitted as true/false instead of 1/0

    Checkbox value in form submitted as true/false instead of 1/0


    Hi,

    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.

    Please help.

    Thanks

  2. #2
    Sencha - Support Team israelroldan's Avatar
    Join Date
    Nov 2011
    Location
    Den Haag, Netherlands
    Posts
    95
    Vote Rating
    11
    israelroldan will become famous soon enough

      0  

    Default


    Which Ext version are you using?
    Can you share your code?
    This seems to work fine: https://fiddle.sencha.com/#fiddle/4ni
    Israel Roldàn | Senior Support Engineer

  3. #3
    Sencha User
    Join Date
    Jul 2013
    Posts
    11
    Vote Rating
    0
    Thinker Bug is on a distinguished road

      0  

    Default


    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

  4. #4
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    415
    Vote Rating
    60
    burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough

      0  

    Default


    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.