2

I want to validate a group of checkboxes so that an error shows is nothing has been selected, hides if at least one checkbox is selected..

I have looked at previous Q&A but for some reason this doesn't work:

<div class="form-group">
    <label class="col-md-5 label" for="checkboxes[]">Question:</label>

    <div class="col-md-7">
        <input id="type1" type="checkbox" name="info[checkboxes[]]" value="value1" class="form-control" required>
        <input id="type2" type="checkbox" name="info[checkboxes[]]" value="value2" class="form-control" required>
        <input id="type3" type="checkbox" name="info[checkboxes[]]" value="value3" class="form-control" required>
        <span class="help-block">Please select at least one type.</span>
    </div>

And in the js file I have the rule:

"checkboxes[]": {
        required: true,
        minlength: 1
      }
user2472368
  • 199
  • 1
  • 6
  • 14
  • Found a solution here: http://stackoverflow.com/questions/18961368/jquery-validation-plugin-checkboxes?rq=1 I have put index of field checkbox in each checkbox name. – user2472368 Apr 09 '15 at 08:01
  • Seems to work -> http://jsfiddle.net/hh9v3a8t/1/ – adeneo Apr 09 '15 at 08:02
  • Yep. I think it wasn't working for me because of other rules I have in the defined in the validate function. – user2472368 Apr 09 '15 at 08:03

0 Answers0