macek / jquery-serialize-object

Converts HTML form into JavaScript object
Other
1.11k stars 352 forks source link

serializeObject() ignoring radio and checkbox inputs #106

Closed dskvr closed 7 years ago

dskvr commented 7 years ago

As an example, the following radio inputs are being ignored by serializeObject(). When using serialize() these inputs are not ignored, as expected.

Note: form code is generated by rails-bootstrap-forms

<label class="radio-inline" for="_form_style_plain"><input type="radio" value="plain" checked="checked" name="[form_style]" id="_form_style_plain"> Default</label>
<label class="radio-inline" for="_form_style_bold"><input type="radio" value="bold" name="[form_style]" id="_form_style_bold"> Bold</label>
<label class="radio-inline" for="_form_style_bolder"><input type="radio" value="bolder" name="[form_style]" id="_form_style_bolder"> Bolder</label>
<div class="checkbox"><label for="_phone_number"><input name="[phone_number]" type="hidden" value="0"><input type="checkbox" value="1" name="[phone_number]" id="_phone_number"> Phone number</label></div>

I've been banging my head for a while, any input? (no pun intended)

dskvr commented 7 years ago

I answered my own question, out of the scope of serializeObject(). rails-bootstrap-forms demonstrates patterns not compatible with serializeObject(), and so these fields are understandably skipped. Workaround was ~to override their field names in the helper.~ write raw HTML for the sake of my sanity.