Reputation: 8505
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
Reputation: 71
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