JQuery validation: validation of at least one checkbox is selected from a list where the names are different

I need to verify that at least one checkbox is selected from a list of checkboxes using the jQuery validation plugin. Since the flags are part of the ASP.NET GridView control, the names of these flags will be different, which allows you to configure the rules for the validation plug-in module, since it expects a name for the rule. I searched around and found the following questions.

  • Question 1710486
  • Question 1136507

I think the first question is a much better solution, but I still feel that this is the wrong way to do it. anyone else has more options for this problem.

+2
jquery jquery-validate validation
source share
1 answer

How about a complex rule that only makes an element mandatory if no other checkboxes have been checked.

rules: { 'require-one': { required : { depends: function(element) { var allBoxes = $('.require-one'); if (allBoxes.filter(':checked').length == 0) { if (allBoxes.eq(element).length != 0) { return true; } } return false; } } } } 

Then you apply the require-one class to each checkbox in the set. The first of them will be required if none of the marked boxes.

+1
source share

All Articles