jQuery Validation plugin - Validating hidden inputs and not visible? [duplicate]
Solution 1:
To allow validation of hidden elements, override the ignore and set it to empty string:
$("#form1").validate({
ignore: "",
rules: {
something: {
number:true,
min:1,
required:true
}
}
});
Solution 2:
You can use ignore
option like this:
$("#form1").validate({
ignore: "input[type='text']:hidden",
rules: {
something: {
number:true,
min:1,
required:true
}
}
});
Default value of ignore
option is :hidden
which ignores all hidden fields and non-visible fields (display: none
etc.)
Solution 3:
If the other answers aren't working for you, try this instead. It removes all ignores for the form, so it would validate everything including hidden fields:
$.data($('form')[0], 'validator').settings.ignore = "";
To restore the settings to ignore hidden fields, use something like this:
$.data($('form')[0], 'validator').settings.ignore = "input[type='text']:hidden";
You can also use the above code to read back the current value.