Add a flag somewhere, indicating whether a dialog box appears, and the user clicks yes. Example:
var userConfirmed = false; $("form").submit(function(e) { if ( userConfirmed ) { userConfirmed = false; // Reset it to false return true; // No need to validate anything, that was already done last time } var form = $(this); // ... "Yes": function() { userConfirmed = true; // Confirm that the dialog was shown and the user clicked "Yes" $(this).dialog("close"); form.submit(); // Try again; this time, the validation was already done }, // ... return false; // Don't submit; the user haven't confirmed the info on the dialog });
Without this flag, you will be in a situation with a chicken and an egg: submit opens a dialog, and a dialog that calls $("form").submit() opens a dialog again ...
If you have many forms and you do not want to use the "global" var, you can use data for the same purpose.
Update live jsFiddle example. Successfully tested in Chrome and Firefox (it displays a blank page 3 seconds after sending).
mgibsonbr
source share