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 Commented Apr 8, 2014 at 18:27
  • That's a different library. Commented Apr 8, 2014 at 18:29
  • Indeed it is, though the solution could have still been helpful. What have you tried? Commented 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. Commented 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'));
});
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.