I have a small form that contains a jQuery UI dialog to ask for additional information if a particular checkbox is checked. The dialog opens and contains 2 additional checkboxes.
The problem is when the form is submitted the 2 checkboxes in the dialog do not get submitted with the rest of the form. From what I can tell when jQuery renders the dialog, it actually renders it outside the closing form tag, causing the checkboxes to not be part of the form anymore.
I have tried things like:
$("#dialog-form").parent().appendTo($("#ContactSpeakerForm:first"));
But have not come up with a good solution.
Here is my js:
$(function() {
var eventReg = $('#dialog-form').dialog({
autoOpen: false,
modal: true,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
});
$('#Confirmed').click(function() {
if($('#Confirmed').attr('checked')) {
eventReg.dialog("open");
}
});
});
Here is the html:
<form id="ContactSpeakerForm" name="ContactSpeakerForm" action="/contacts/add-contact-speaker/id/3420" method="post">
<input type="hidden" name="ID" value="" id="ID">
<input type="hidden" name="Contact_ID" value="3420" id="Contact_ID">
<div class="page_panel_table">
<table>
<tbody>
<tr>
<td align="right" class="form_label">Confirmed:</td>
<td>
<input type="checkbox" name="Confirmed" id="Confirmed" value="1">
</td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Save"></td>
</tr>
</tbody>
</table>
</div>
<div id="dialog-form" style="display:none;" title="Speaker Event Registration">
<input type="checkbox" name="RegisterForEvent" id="RegisterForEvent" value="1">
<input type="checkbox" name="RegisterForDinner" id="RegisterForDinner" value="1">
</div>
</form>
Anyone know a good solution?
After setting up your dialog, use:
There are two key things here. First, you run this after the widget has had a chance to initialize and change the mark up. Second, you remove the dependence on the direct parent/child relationship.