Validating a group of checkboxes.

3 posts, 0 answers
  1. Ziad
    Ziad avatar
    1 posts
    Member since:
    Jun 2013

    Posted 12 Jul 2013 Link to this post

    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. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 15 Jul 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 15 Jul 2013 Link to this post

    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!
Back to Top