0

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
});
4
  • 1
    Perhaps related to this: stackoverflow.com/questions/9129029/jquery-validation-onclick
    – Derek
    Apr 8, 2014 at 18:27
  • That's a different library.
    – mishap
    Apr 8, 2014 at 18:29
  • Indeed it is, though the solution could have still been helpful. What have you tried?
    – Derek
    Apr 8, 2014 at 18:34
  • I tried finding the solution in their documentation. I guess I have to switch to more popular validation library you referred to.
    – mishap
    Apr 8, 2014 at 18:43

1 Answer 1

1

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'));
});
1
  • I tried to find the diffrent ways of manual validation. But i got to the point, that i can't get config from the plugin. Apr 8, 2014 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.