When using the jQuery submitHandler method, I'm posting the form data via ajax to the server. On success, another method is called that resizes a popup and notifies the user its all complete.
My problem is however, whilst posting the data, the form is getting validated again causing undesired effects.
My understanding is submitHandler shouldn't trigger the validation again?
submitHandler: function(form) {
console.log('test');
}
In this instance, 'test' is being logged to the console, but the validation is being run once again (in this case, a server side validity check on an email address field).
I'm using a button type submit as the form element. Do I need to prevent defaults or something similar?
fn , so simply check whether it exists or not; if (typeof jQuery. fn. validationPlugin === "function") { // It's loaded } else { // It's not. }
The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form. You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.
Definition of jQuery validate errorplacement. The jQuery validate errorplacement() function is used to customize the placement of an error message. This function is a built-in function in jQuery. These function changes the default behavior of the validation plugin to insert the error label after the input fields.
An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.
Your submitHandler
should exist within the validate
function. In addition you should call form.submit()
yourself which will remove the recursive calls that would otherwise exist.
$("#myForm").validate({
submitHandler: function (form) {
console.log('test');
form.submit();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With