Validation of a field which is hidden in ASP.NET MVC

The case is that i have a field that uses the popuylar library Chosen, so it can offer an easier way to choose an element from a multiselect list.

Basically what the library does is copying the content of the dropdown and making a separate one, which in its case kills the validation of the original field, which I did setup on the server side in example like adding an attribute Required over the field.

Adding the JS below will make your client side code validate even hidden fields.

var validator = $("form").data('validator');
if (validator != null) {
if (validator.settings != null) {
validator.settings.ignore = ":hidden:not(select)";
}
}

You may also like...