I have the following piece of html code for form checkboxes
-
Try
adding this code will do
var chck = $('input[type=checkbox]');
chck.addClass('check-one');
$.validator.addMethod('check-one', function (value) {
return (chck.filter(':checked').length > 0);
}, 'Check at least one checkbox');
fiddle Demo
Group will show error in front first check-box only
var chck = $('input[type=checkbox]');
chck.addClass('check-one');
$.validator.addMethod('check-one', function (value) {
return (chck.filter(':checked').length > 0);
}, 'Check at least one checkbox');
var chk_names = $.map(chck, function (el, i) {
return $(el).prop("name");
}).join(" ");
$("#submitDetails").validate({
groups: {
checks: chk_names
},
submitHandler: function (form) {
alert('Form Submited');
return false;
}
});
Remove group if you want error to show in front of all check-boxes
fiddle Demo
$("#submitDetails").validate({
submitHandler: function (form) {
alert('Form Submited');
return false;
}
});