I have several forms with separate validators defined. These all work fine and validates as expected. However if I click the cancel button in the dialog box it still validates the form and shows errors. I have to click the cancel button twice for the form to close. If I click the [x] to close the dialog I briefly see the error message but the form closes. I can live with that.
This is my code:
var renewValidator = $("#FormRenew").validate({
rules: {
NewNo: {
remote: {
url: "action.php?checkDup=1"
}
}
}
});
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
width: 450,
modal: true,
buttons: {
'Renew': function() {
if (renewValidator.valid()) {
$.ajax({
type: "POST",
url: "ajax.php",
data: queryString,
success: function(msg) {...
}
});
$(this).dialog('close');
}
},
Cancel: {
text: 'Cancel',
immediate: "true",
formnovalidate: 'formnovalidate',
class: 'cancel',
click: function(e) {
console.log('Cancel clicked!');
e.preventDefault();
$("form").validate().cancelSubmit = true;
$(this).dialog('close');
}
}
},
beforeClose: function() {
renewValidator.resetForm();
$("#FormRenew").trigger("reset");
}
});
Initially I just had a simple cancel like this Cancel:
function() {
$(this).dialog('close');
}
But I added the various options as suggested in other posts. None works for me.