I have several forms on one page, and I want to add a confirmation dialog to all those using the same code. All of them have a class of a confirmation form, and the title of the confirmation dialog should be generated dynamically (which does not work atm).
In html, I have a dialog that hides when the page loads, then it is displayed after the function is called dialog('open').
This is what I have now, and it just doesn’t work at all, the dialog loads, but as soon as you click confirm, it repeats the else clause a lot and does not submit the form:
var deleteConfirmed = false;
$('form.confirm-form').submit(function(e) {
if ( ! deleteConfirmed)
{
e.preventDefault();
var title = $(this).find('input.action').val();
var $this = $(this);
console.log('title: ' + title);
$('#confirm-dialog').attr('title', title);
$('#confirm-dialog').dialog({
buttons : {
"Confirm" : function() {
deleteConfirmed = true;
$(this).dialog('close');
$this.submit();
},
"Cancel" : function() {
$(this).dialog('close');
}
}
});
$('#confirm-dialog').dialog('open');
}
else
{
$(this).submit();
deleteConfirmed = false;
}
});
source
share