JQuery Validation - disable onfocusout for only one field

Is there a way to ignore the onfocusout property for a single field of a 5 form using the jQuery validation plugin?

I mean, the jQuery validation plugin is currently validating the onblur element of this form field. I would like the plugin not to do this for only one form field. He can save this check for other form fields.

How can i do this?

Thank,

+5
source share
1 answer

You can override the event handler onfocusoutin the parameters that you pass to the method .validate(). In the overridden version, some element should be processed, returning to the default, if this is not the field that 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);
        }
    }
});

jsFiddle .

+14

All Articles