DOM jsFiddle detection and two issues become apparent.
If you want the jQuery Validate plugin to automatically capture the click event of the submit button ...
- the button should be
type="submit" - The button should be in the
<form></form> container.
These two conditions must be met if you want the plugin to work as intended.
You also incorrectly placed the .validate() method in the success callback of your submit modal dialog box.
The .validate() method is used only to initialize the plugin and should be called once after the form is created.
EDIT
After playing with this, it becomes obvious that the Bootbox modal plugin may have some critical limitations that interfere with the form submission.
I can initialize the validation and work as it should, but the dialog is rejected before the actual presentation of the form occurs. There may be a solution, but after looking at the documentation for Bootbox this is not obvious.
https://jsfiddle.net/vyaw3ucd/2/
EDIT 2:
In accordance with the OP decision ...
bootbox.dialog({ // other options, buttons: { success: { label: "Submit", className: "btn btn-sm btn-primary", callback: function () { if ($("#webteamContactForm").valid()) { var form = $("#webteamContactForm"); form.submit(); // form submits and dialog closes } else { return false; // keeps dialog open } } } } });
However, simply by using the supplied form argument directly, you have no errors when using the submitHandler parameter of the jQuery Validate plugin.
submitHandler: function (form) { console.log("Submitted!"); form.submit(); }
DEMO: https://jsfiddle.net/vyaw3ucd/5/
source share