Skip to content

Instantly share code, notes, and snippets.

@csalgueiro
Created January 20, 2014 08:53
Show Gist options
  • Save csalgueiro/8516983 to your computer and use it in GitHub Desktop.
Save csalgueiro/8516983 to your computer and use it in GitHub Desktop.
Validar un grupo de checkboxes exigiendo que esté marcado más de uno From http://stackoverflow.com/questions/2445010/jquery-validation-plugin-validating-checkboxes-with-different-names
$.validator.addMethod('require-one', function (value) {
return $('.require-one:checked').size() > 0; }, 'Please check at least one box.');
var checkboxes = $('.require-one');
var checkbox_names = $.map(checkboxes, function(e,i) { return $(e).attr("name")}).join(" ");
$("#itemForm").validate({
groups: { checks: checkbox_names },
errorPlacement: function(error, element) {
if (element.attr("type") == "checkbox")
error.insertAfter(checkboxes.last());
else
error.insertAfter(element);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment