JQuery Validation plug-in - disabling validation based on class attributes

How can I configure the jQuery Validation plugin to disable class attribute based validation and just work based on json rules?

This is contrary to my jQuery template system.

+4
source share
3 answers

First, your jQuery ready function has a class set to ignore or require for each element:

$("#name").attr("class", "required"); $("#email").attr("class", "ignore"); 

Second, set the validation function to ignore the ignore class:

 $("#form1").validate({ignore: ".ignore"}); 

This will require a name, but ignore the letter.

+2
source

Looking at the source jquery.validate.js, there is a variable called classRuleSettings that stores validation types based on class names. Set it to an array of length 0, and you will say that it is good.

Try it():

 <form> <input type="text" class="required"/> <input type="Submit"/> </form> <script type="text/javascript"> $.validator.classRuleSettings = []; //I am not sure about any side effects because of this $("form").validate(); </script> 
+1
source

You can use the ignore option

 $("form").validate({ignore:".ignore"}); <input type="text" id="fName" class="required ignore"/> <!--fname won't be "required"--> 
0
source

Source: https://habr.com/ru/post/1337606/


All Articles