I'm running into a bit of trouble with the jQuery validate plugin.
I have a form with some name array checkboxes and corresponding name array radio inputs.
What I'm after is to only validate the action[] inputs when the (not required) check[] input has been checked.
$(document).ready(function(){
$("#testForm").validate({
rules: {
'action[]': {
required: function () {
return $("'check[]':checked");
}
}
}
});
});
<form id="testForm" name="testForm" method="post" action="" >
<table cellpadding="1" cellspacing="1" border="1">
<tr>
<th> </th>
<th>Include</th>
<th>Action</th>
</tr>
<tr>
<th>Row[0]:</th>
<td><input type="checkbox" name="check[0]" value="Y" /></td>
<td>
<input type="radio" name="action[0]" class="required" value="ON" />ON<br/>
<input type="radio" name="action[0]" class="required" value="OFF" />OFF<br/>
<label class="error" for="action[0]" generated="true"></label>
</td>
</tr>
<tr>
<th>Row[1]:</th>
<td><input type="checkbox" name="check[1]" value="Y" /></td>
<td>
<input type="radio" name="action[1]" class="required" value="ON" />ON<br/>
<input type="radio" name="action[1]" class="required" value="OFF" />OFF<br/>
<label class="error" for="action[1]" generated="true"></label>
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
I have set up a jsfiddle to hopefully explain the problem in more detail:
http://jsfiddle.net/h2dt4t30/2/
Any help or guidance would be appreciated.
Thanks in advance