Is there a way to ignore "onfocusout" property for one form field out of 5 using Jquery validation plugin?
I mean, Jquery validation plugin currently validates an element onblur of that form field. I would like the plugin to not do so for one form field only. It can keep that validation for other form fields.
How can I do this?
Thanks,
You can override onfocusout
event handler in the options you pass to the .validate()
method. The overriden version should which element is being handled, falling back to the default behaviour if it is not the field you want to exclude:
$('#test').validate({
rules: {
"field1": "required",
"field2": "required",
"field3": "required"
},
onfocusout: function (element, event) {
if (element.name !== "field2") {
$.validator.defaults.onfocusout.call(this, element, event);
}
}
});
See this jsFiddle for full demo.
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