How to set the value for Radio Buttons When edit?

后端 未结 6 1683
忘了有多久
忘了有多久 2020-12-14 18:53

I have a Gender Row with radio buttons male & female. when i register as first time the values of radio button will store in database. Now my question is if i edit that

6条回答
  •  醉梦人生
    2020-12-14 19:05

    For those who might be in need for a solution in pug template engine and NodeJs back-end, you can use this:

    If values are not boolean(IE: true or false), code below works fine:

    input(type='radio' name='sex' value='male' checked=(dbResult.sex ==='male') || (dbResult.sex === 'newvalue') )
    input(type='radio' name='sex' value='female' checked=(dbResult.sex ==='female) || (dbResult.sex === 'newvalue'))
    

    If values are boolean(ie: true or false), use this instead:

    input(type='radio' name='isInsurable' value='true' checked=singleModel.isInsurable || (singleModel.isInsurable === 'true') )
    input(type='radio' name='isInsurable' value='false' checked=!singleModel.isInsurable || (singleModel.isInsurable === 'false'))
    

    the reason for this || operator is to re-display new values if editing fails due to validation error and you have a logic to send back the new values to your front-end

提交回复
热议问题