Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validate - Success event?

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?

like image 685
Probocop Avatar asked Apr 05 '12 10:04

Probocop


People also ask

How do you check if jQuery validate is working?

The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.

What does jQuery validate do?

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.

Does jQuery validate require a form?

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.

What is jQuery validate unobtrusive?

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.


2 Answers

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
    }
});
like image 184
Starx Avatar answered Sep 27 '22 22:09

Starx


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(...);
    }
});
like image 41
Ryley Avatar answered Sep 27 '22 21:09

Ryley