I am attempting to call the jQuery validation showErrors
function from within the submitHandler
function without having to saving the validator object like so:
var validator = $( "#myshowErrors" ).validate();
validator.showErrors({
"firstname": "I know that your firstname is Pete, Pete!"
});
Is there a way to get the get the validator object from within the submitHandler
method somewhat like this:
$( "#myshowErrors" ).validate({
submitHandler : function(form) {
$(form).ajaxSubmit({
success : function(result) {
var validator = // Get validator here somehow?
validator.showErrors(result.fieldErrors);
}
});
}
});
By doing it this way, my hope is that I can use the same submitHandler
method in multiple places throughout my project.
Validator object is stored in form element data:
var validator = $.data( form, "validator");
Edit:
In fact validator should be also stored in this
:
$( "#myshowErrors" ).validate({
submitHandler : function(form) {
var validator = this;
$(form).ajaxSubmit({
success : function(result) {
validator.showErrors(result.fieldErrors);
}
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With