11

I have a simple validate block like this:

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

When the user clicks a certain button, I would like to change that ignore rule to ignore: [] , then validate it and then switch back. I realize I could use classes instead but I want to know if there is a way around that.

Edit: It should be noted that ignore: [] is the proper way to do it when using .validate().

Falantar014
  • 405
  • 2
  • 5
  • 20
  • 1
    Also see this answer for proper implementation of `ignore: ''`: http://stackoverflow.com/a/8565769/594235 – Sparky Apr 16 '13 at 20:10

1 Answers1

20
$('#myForm').validate().settings.ignore = "newIgnore";

The validate() method returns you a reference to the validator object you created with your original validate() call.

You can then call the property .settings.ignore

politus
  • 5,996
  • 1
  • 33
  • 42
  • 1
    Thank you, I don't know how I wasn't able to find this myself. – Falantar014 Apr 16 '13 at 19:11
  • @Falantar014 Probably because it's a needle in a haystack. I've just tried 50 different things that you'd expect to reset or "forget" the old ignore setting (including your extremely reasonable approach put forward in the question) . But nope, only this. – Josh Sutterfield Jan 29 '16 at 22:37
  • This is what I ended up doing after I found out `validate()` caches the validator the first time it's created and then ignores any new options passed to it in successive calls. – Scutterman May 16 '19 at 10:59