0

i am use asp.net mvc 5, about jquery validate unobtrusive, jquery validate is 1.13 version. I have searched very much answer, Although this problem have solve,But I want to know another method.

$.validator.setDefaults({ ignore: [] });   //valid

$("#form1").data("validator").settings.ignore = []; //invalid,all input validate invalid

$("#form1").data("validator").settings.debug = true;//valid,if use this method,debug ture model is open, why?

if put code in $(document).ready. all code is useless

how Enable validation for hidden fields only for one form?

SuperJLive
  • 43
  • 8

1 Answers1

0

Instead of enabling the validation for all hidden fields , its better to enable validation for only the ones you want.

you can do this by assigning a class to the hidden fields you want to validate and then using the following code.

// Add special-hidden class to the hidden fields you want to validate.
var validator = $("#formID").validate({ rules: rules });
// this line basicially tells the validator to ignore hidden fields apart from the ones with class special-hidden
 validator.settings.ignore = ':hidden:not([class~=special-hidden])';

If you want to enable validation for all hidden fields , use

 validator.settings.ignore = ''; 
Pratik
  • 868
  • 1
  • 9
  • 24