Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery validate ignore [] and more

I need to validate hidden fields, so I have this below (validate hidden fields)

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

I would like to ignore a certain class as well, but I'm not sure of the syntax to get both.

$.validator.setDefaults({ ignore: "[], .ignoreThisClass" });

This obviously does not work but how can I specify to both validate hidden and ignore my class?

like image 897
aw04 Avatar asked Mar 24 '14 15:03

aw04


People also ask

What is ignore in jQuery validation?

It's an array of jquery selectors. If the element matches the selector, it is ignored.

How do you check whether a form is valid or not in jQuery?

$("#form_id"). valid(); Checks whether the selected form is valid or whether all selected elements are valid. validate() needs to be called on the form before checking it using this method.

What is Errorplacement?

Definition of jQuery validate errorplacement. The jQuery validate errorplacement() function is used to customize the placement of an error message. This function is a built-in function in jQuery. These function changes the default behavior of the validation plugin to insert the error label after the input fields.

What is jQuery validate unobtrusive?

An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.


1 Answers

Add your class to the array instead.

$.validator.setDefaults({ ignore: [".ignoreThisClass"] });

It's an array of jquery selectors. If the element matches the selector, it is ignored. By default it is [":hidden"] which is why making it [] makes it allow hidden elements.

like image 130
Kevin B Avatar answered Sep 29 '22 02:09

Kevin B