3

I am using jQuery unobtrusive validation on a form. Some fields are hidden, and some of these hidden fields require validation and others do not. I understand in order to validate hidden fields I can do this:

var validator = $("form").data("validator");
validator.settings.ignore = "";

But this then validates all hidden fields. How do I specify which hidden fields should be validated?

3 Answers 3

6

You can add a class(like validate) to those hidden fields which has to be validated then

validator.settings.ignore = ":hidden:not(.validate)";
0
1

Put a class on the fields to ignore, such as validator-ignore, then set that selector in the property:

validator.settings.ignore = ".validator-ignore";
1

Ok. Here is what worked for me

$.validator.setDefaults({
            ignore: ":hidden:not(.validate)"
        });

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.