mishap
mishap

Reputation: 8505

jQuery Form Validator validate on button click

I'm using jQuery Form Validator and I need to validate the form on button (not submit) click. Cannot figure out how to do it.

I have set it up with custom error messages :

$.validate({
    language: myLanguage
});

Upvotes: 0

Views: 637

Answers (1)

kot-6eremot
kot-6eremot

Reputation: 71

http://formvalidator.net/#configuration_callbacks

You can use it like that:

$.validate({
form : '#registration-form',
modules : 'security',
onError : function() {
  alert('Validation failed');
},
onSuccess : function() {
  alert('The form is valid!');
  return false; // Will stop the submission of the form
},
onValidate : function() {
  return {
    element : $('#some-input'),
    message : 'This input has an invalid value for some reason'
  }
}
});

Or use an event listeners:

$('input')
.bind('beforeValidation', function() {
  console.log('Input "'+this.name+'" is about to become validated');
})
.bind('validation', function(evt, isValid) {
  console.log('Input "'+this.name+'" is ' + (isValid ? 'VALID' : 'NOT VALID'));
});

Upvotes: 1

Related Questions