I have a JQuery UI modal dialog box in the form of an HTML (well ...) form
with select
and input
(checkbox) controls. The dialog box and the controls work as one would expect, except that the controls retain their new states (e.g. checkbox selected) even if I close the dialog boxes window (or press a button "Cancel").
Is there any mechanism whereby I can make a jQuery UI dialog box retain the old control states when a certain exit button (e.g. "Cancel") is pressed, or do I have do roll my own state management in JavaScript (I hope not).
Here's an example of what currently happens and should not:
- Enter dialog box.
- Checkbox is off.
- Change checkbox from off to on.
- Close dialog box window.
- Open it again.
- Checkbox is on (I want it to be off, because the dialog box was previously "cancelled").
UPDATE Here is a relevant portion of my HTML, including a call to clone()
.
<script>
$(function() {
var dialog = $("form.dialog").clone().dialog({
autoOpen: false,
height: 300,
width: 300,
modal: true,
buttons: [
{
text: "Ok",
click: function() {
$(this).submit();
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}
}
]
});
$(“#dialog-button”).on("click", function() {
dialog.dialog("open");
return false;
});
});
</script>
<form hidden method="post" action="" class="dialog" class="ui-dialog-titlebar ui-widget-header" title=“Test”>
<select name="name">
</option>
<option value="value">
Test
</option>