I am using the jQuery Validate plugin on my site, and then submitting the form via ajax. Is there an event I can use when the entire form is valid?
The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.
We're going to use the jQuery Validation Plugin to validate our form. The basic principle of this plugin is to specify validation rules and error messages for HTML elements in JavaScript.
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.
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.
There is no event for this. Just check the status using a simple if statement.
if($("form").valid()) {
//go ahead
}
But, if you are trying to have a workaround solution to catch the valid event, you can do something like this
$("form").submit(function() {
if($(this).valid()) {
//go ahead
} else {
//do some error handling
}
});
The way jQuery Validate wants you to deal with this is by specifying a submitHandler
aka "run this function when the form is submitted AND it is valid". You would submit the contents of the form via AJAX from within that function.
$('form').validate({
//your normal options
submitHandler: function(){
$.ajax(...);
}
});
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