문제

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)"
        });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top