I am trying to use jQuery Validate plugin addMethod for validating multiple fields of similar validation conditions. Those fields are required depending on another dropdown selection. How can I use required:true property inside an addMethod?
All I can think of is JS code to check if the field is empty. But I want a cleaner way.
Here's the code:
HTML:
<td>
<input type="text" name="examname1" id="en1" maxlength="8" size="8" disabled="disabled" onkeypress="return isAlphaKey(event)" />
</td>
jQuery :
//common validation method for education details in first row
jQuery.validator.addMethod ("prox_education1", function (value, element) {
if ($("#education").val() >= 1)
{
?????
}
}, "This field is required");
How do I make the field required if the condition is true?
jQuery.validator.addMethod (...) {
if (condition)
{
make this element required
}
else
{
ignore
}
"Error: This field is required and you left it blank"