Reputation: 5238
I've got three input fields: NAME, AGE, COUNTRY
I want to check if NAME is anything. If NAME contains a value then the two other fields is required. If NAME is empty they can also skip AGE and COUNTRY.
Is this possible with jquery validate?
My current validation is based on a classname and then I've got the following in my js file:
beforeSubmit: function () {
return $('#ajaxform').validate().form();
}
Upvotes: 0
Views: 2740
Reputation: 100175
you can use depends, like:
...
ageInput: {
required: {
depends: function(element){
return $("#nameElement").val()!=""
}
}
},
countryInput: {
required: {
depends: function(element){
return $("#nameElement").val()!=""
}
}
}
See: jquery Validate
Upvotes: 1