radio box option with associated value 0 pre-checked

radio box option with associated value 0 pre-checked

LimpEmuLimpEmu Posts: 65Questions: 18Answers: 1

I noticed that if a radio box option has the value 0, it is always pre-checked for a new, empty form, e.g.:

{label:"EGD History",name:"cmegdh",type:"radio", options:[{label:"Yes",value:1},{label:"No",value:0}]}

will have the No checked, while:

{label:"EGD History",name:"cmegdh",type:"radio", options:[{label:"Yes",value:1},{label:"No",value:2}]}

will have both options empty (the way I prefer it).

I can address this by changing the value in my DB from 0 to 2 before loading the data into editor/datatables and reverse this process before writing data to my DB, but I am wondering whether I am missing something here, i.e., whether there is a more obvious solution. Is this behavior intentional?

Thank you!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    I think its just doing a falsy comparison at that point, so 0 == ''.

    If you use:

    options:[
      {label:"Yes",value:"1"},
      {label:"No",value:"0"}]
    }
    

    that should do it. Let me know how you get on with it.

    Allan

  • LimpEmuLimpEmu Posts: 65Questions: 18Answers: 1

    Of course, you are right. That works!
    Now on to the next puzzle ...

This discussion has been closed.