I need some guidance on how to add a validation method to the jquery validate plugin. I've gathered that i need to use the plugin's addMethod() function, but how exactly to have it do what i need... Here i am!
My form 's first question is a radio input choice. Each radio input, if selected, shows a sub-question of several checkboxes.
What i would like my validation to do is: - make sure one radio input is selected - make sure at least one checkbox pertaining to the radio input is selected.
Basically, out of the validate plugin's own logic, i would count the selector's length, and if there isn't any, return the error message. Something like this:
var weekSelected = ($('input.seasonSelector:checked input.weekSelector:checked',form).length > 0);
if(!weekSelected){
return 'Please select a week inside that season';
}
How to turn that into a validate plugin method ?
UPDATE
here is the successful answer, based on your feedback:
$('#newInscription').validate({
rules: {
"season_id": "required",
"weeks[]": {
required: {
depends: function() {
return $(this).parents(".seasonSelector:checked");
}
}
}
}
,
...