Im having an issue where the my jquery UI dialog loads multiple times on top of itself:
click -> opens dialog(1 time) -> close dialog
click - > opens dialog(2 times) -> close dialog
click - > opens dialog(4 times) -> close dialog
click - > opens dialog(8 times) -> close dialog
Exactly what is described here: Why does my modal jQuery dialog open multiple times?
I following solution worked for that person but it did not work for me. The solution that worked for that person was to:
1) initialize the dialog outside the function
2) open only on the successful callback from load()
As you can see I do both things in the following code but the problem still persists. Please help:
(Btw the general structure is I load a dialog on the click of a link. Then when the Register button inside that dialog is clicked, I load another small confirmation dialog on top of it with an OK button that closes both dialogs.)
$(document).ready(){
var $registerDialogHandle = null;
var $registerStatusDialogHandle = null;
$registerDialogHandle = $('<div></div>').html("").dialog({
autoOpen: false, modal: true, width: 470, height: 552,
buttons: {
"Register": function () {
if ($('#registerForm').validate().form()) {
$.ajax({
...ajax settings...
success: function () {
openInDialog($registerStatusDialogHandle, "/Account/RegisterStatus");
}
});
}
}
}
});
$registerStatusDialogHandle = $('<div></div>').html("").dialog({
autoOpen: false, modal: true, width: 365, height: 165,
buttons: {
"OK": function () {
$(this).dialog("close");
$registerDialogHandle.dialog("close");
}
}
});
$('.registerLink').live("click", function () {
openInDialog($registerDialogHandle, "/Account/Register?path=_RegisterPartial");
});
} /*End of document.ready()*/
function openInDialog(dialog, target) {
var $url = target;
var $dialog = dialog;
$dialog.empty();
$dialog.dialog("option", "position", "center").load($url, function () {
$dialog.dialog("open");
});
}
Seems to work ok here, if I change the
.remove()calls to.hide()calls:http://jsfiddle.net/jtbowden/s6SxE/