I've been struggling with this for a while, so I thought to seek help.
I hava a div filled with checkboxes and I need to validate if at least one checkbox was checked.
<div data-val="true" data-type="list-checkbox">
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</div>
Is there a way to use "jQuery.validator.addMethod" to add a validation to that particular DIV? I think it would be a lot cleaner if I could just add a function to validate, instead of injecting a javascript to validate before submitting the form.
I have tried something like this:
jQuery.validator.addMethod('requiredCheckboxList', function (value, element, params) {
var div = $(element);
//Some code to iterate through the div and check if at least one is checked
}, 'Wops!');
but it seems that the default behavior of the valitator does not check for divs marked as "data-val=true"
Thanks!