This is a migrated thread and some comments may be shown as answers.

Validating a group of checkboxes.

2 Answers 296 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Ziad
Top achievements
Rank 1
Ziad asked on 12 Jul 2013, 03:00 PM
I have a group of checkboxes that I need to validate that at least 1 of them is selected.  How do I go about doing this?

Code:
<div class="row-fluid">
  <span class="span3">
    <input type="checkbox" value="abc" />abc
  </span>
  <span class="span3">
    <input type="checkbox" value="def" />def
  </span>
  <span class="span3">
    <input type="checkbox" value="hij" />hij
  </span>
</div>
<div class="row-fluid" id="button-bar">
  <button>Submit</button>
</div>

var validator = $('.row-fluid').kendoValidator().data('kendoValidator');
 
$('#button-bar').on('click', 'button', function(e) {
  if (!validator.validate()) {
    alert("Failed");
    return;
  }
  alert("Passed");
});
Thanks to anyone that can help me out on this.

2 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 15 Jul 2013, 03:53 PM
Hello Ziad,

Checkboxes by nature are optional and not required. You can perform custom validation when you submit the form and prevent submitting if there are no checked checkboxes.

For your convenience here is a jsBin example which demonstrates a possible implementation.
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kiril Nikolov
Telerik team
answered on 15 Jul 2013, 03:55 PM
Hi Ziad,

Checkboxes by nature are optional and not required. You can perform custom validation when you submit the form and prevent submitting if there are no checked checkboxes.

For your convenience here is a jsBin example which demonstrates a possible implementation. 

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Validation
Asked by
Ziad
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or