markgx / jquery-check-all

Quickly add check all/uncheck all functionality to your forms or tables.
http://markgx.github.io/jquery-check-all
33 stars 13 forks source link

Trigger "change" event #4

Open AlexeyKosov opened 8 years ago

AlexeyKosov commented 8 years ago

Currently it doesn't trigger "change" event for children checkboxes so there's no way to perform an action after all the checkboxes are checked/unchecked.

durdenk commented 8 years ago

+1 for this. I need to count all checkboxes and selected checkboxes and report to user, Upon clicking checkbox, it does that but in wrond order.

adaniello commented 8 years ago

Simply update line 23 in

$children.prop('checked', $(this).prop('checked')).change();

(fire change on childrens)

bs-thomas commented 7 years ago

FYI this is what I've done 2 years ago.

  checkAll.prototype.init = function() {
    this._checkChildren();

    var plugin = this;

    this.$el.on('change', function(e) {
      var $children = $(plugin.options.childCheckboxes, plugin.options.container).not(plugin.$el);

      // 2015/9/5 modified by Thomas @ BeamStyle: Modification to only change checkboxes that need change, and then triggering the change event for those checkboxes
      var isChecked = $(this).prop('checked');
      $children = isChecked ? $children.not(':checked') : $children.filter(':checked');
      $children.prop('checked', $(this).prop('checked')).trigger("change");
    });

    $(this.options.container).on('change', plugin.options.childCheckboxes, function(e) {
      plugin._checkChildren();
    });
  };