Sander
Sander

Reputation: 13431

How to fire code in case of a success or failed form validation with jQuery validate

It seems that jQuery validate plugin does not come with out of the box, success and failed callback options. How do I manage to launch some custom code when a form's validation fails?

We need to change certain layout elements not related to the fields itself when a player enters invalid data.

Hope it is still possible

Upvotes: 0

Views: 82

Answers (1)

Nick Craver
Nick Craver

Reputation: 630509

These options are included, just not as intuitively named as possible, they're submitHandler and invalidHandler, like this:

$("form").validate({
  invalidHandler: function(form, validator) {
    //this runs when the form is invalid, not submitted
  },
  submitHandler: function(form) {
    //this runs when the form is is valid
  }
});

Upvotes: 4

Related Questions