I'm using jQuery 3.1.1 (the latest version as of this post) and the Uniform plugin (just including in case this matters - likely doesn't) to make checkboxes look nice.
I'm encountering the following:
-
Within a Form, I'm using MVC/Razor's
CheckBoxFor
to render a regular checkbox input and hidden additional input for the checkbox in addition to other inputs. This results in code like this:<input id="mycheckbox" name="mycheckbox" type="checkbox" value>
<input name="mycheckbox" type="hidden" value>
-
For test purposes, I'm checking the box on the UI.
- I verified that the checkbox input is now true (via
$("#mycheckbox").prop("checked")
) but the hidden input is false (same verification). I'm not sure if this is the culprit or not - in that case it may be a uniform issue. - When then calling $form.serialize() on that form, both inputs (checkbox and hidden) are serialized to nothing, meaning
&mycheckbox=&mycheckbox=
So, two issues:
- Somehow
serialize()
doesn't get that the regular checkbox input is checked - There is double-serialization, but I suppose
serialize()
is just grabbing all input's so this is probably fine.
How can I solve #1?
Aucun commentaire:
Enregistrer un commentaire