javascriptjquerytwitter-bootstraponselect

Unchecked checkbox when check all checkboxs bootstrap


I have the next HTML code:

          <div class="form-group">
              <div class="col-sm-12 divider">
                <br><label><input type="checkbox" class="checkbox selectAll" value="">Select All</label>
              </div>
          </div>
          <div class="form-group">
              <div class="col-sm-12 ">
                <label><input type="checkbox" class="checkbox" value="">CHS Informed Consent Form</label>
              </div>
              <hr/>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Order Sets</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Carboplatin Teaching Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Bevacizumab Teaching Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">CHS Specialty Pharmacy Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Calendar</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Healthcare Provider Contact Form</label>
              </div>
          </div>
          <div class="form-group">
              <div class="col-sm-12">
              <button type="submit" class="btn btn-default submit">Generate Super Pack</button>
            </div>
          </div>

        </form>

And the next jquery code:

This toggle the styles

$('.checkbox').checkbox({
    buttonStyle: 'btn-link',
    buttonStyleChecked: 'btn-inverse',
    uncheckedClass: 'icon-check-empty',
    checkedClass: 'btn-inverse'
});

If I want to check all boxes I use:

$(".selectAll").click(function () {
    $('input:checkbox').not(this).prop('checked', this.checked);
});

But my problem is, when I have one or more item selected and then I choose select All the checked items go unchecked. I'm using bootstrap-checkbox.js
But I can not figure out how solve the problem.

Any idea?

Thank you.


Solution

  • You can use checkbox options to enable/disable them all

    $('input:checkbox').not(this).checkbox({checked: this.checked});
    

    http://jsfiddle.net/D2RLR/7108/