How to make sure at least 1 checkbox is checked with jQuery Validate
I have a group of checkboxes that each have their own name, so they are not a checkbox group. I need a custom method for jQuery Validate that will make sure 1 or more is checked. Also, typically you tie a validation method to开发者_运维知识库 a field, but this covers lots of fields, so is therea jQuery Validate function that allows me to tie this to the submit so that it runs along with the other typical field required checks when the submit button is pressed?
Example checkboxes:
<form id="form" name="form>
<input type="checkbox" name="app1" value="y" />App 1
<input type="checkbox" name="app2" value="y" />App 2
<input type="checkbox" name="app3" value="y" />App 3
<input type="checkbox" name="app4" value="y" />App 4
<input type="submit" value="Submit">
</form>
You can just check to see if any of the forms children are checked.
if (!$('#form').children(':checked').length) return false;
精彩评论