You can add a class(like validate
) to those hidden fields which has to be validated then
validator.settings.ignore = ":hidden:not(.validate)";
سؤال
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?
المحلول
You can add a class(like validate
) to those hidden fields which has to be validated then
validator.settings.ignore = ":hidden:not(.validate)";
نصائح أخرى
Put a class on the fields to ignore, such as validator-ignore
, then set that selector in the property:
validator.settings.ignore = ".validator-ignore";
Ok. Here is what worked for me
$.validator.setDefaults({
ignore: ":hidden:not(.validate)"
});