Sha256: f2e56bf409230b167e219fa49e21fa2c640f35b2f044ec193a99a9c6756542c5

Contents?: true

Size: 1.24 KB

Versions: 15

Compression:

Stored size: 1.24 KB

Contents

((exports) => {
  class MaxChoicesAlertComponent {
    constructor(options = {}) {
      this.wrapperField = options.wrapperField;
      this.alertElement = options.alertElement;
      this.controllerFieldSelector = options.controllerFieldSelector;
      this.controllerCollectionSelector = options.controllerCollectionSelector;
      this.maxChoices = options.maxChoices;
      this.controllerSelector = this.wrapperField.find(this.controllerFieldSelector);
      this._bindEvent();
      this._run();
    }

    _run() {
      const rows = this.wrapperField.find(this.controllerCollectionSelector);

      let alert = false;

      rows.each((rowIdx, row) => {
        const checked = $(row).find(this.controllerFieldSelector).filter((checkboxIdx, checkbox) => $(checkbox).is(":checked"));

        alert = alert || checked.length > this.maxChoices;
      });

      if (alert) {
        this.alertElement.show();
      }
      else {
        this.alertElement.hide();
      }
    }

    _bindEvent() {
      this.controllerSelector.on("change", () => {
        this._run();
      });
    }
  }

  exports.Decidim = exports.Decidim || {};
  exports.Decidim.createMaxChoicesAlertComponent = (options) => {
    return new MaxChoicesAlertComponent(options);
  };
})(window);

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-forms-0.24.3 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.6 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.24.2 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.5 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.24.1 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.24.0 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.24.0.rc2 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.4 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.24.0.rc1 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.3 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.2 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.1 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.1.rc1 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.23.0 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6
decidim-forms-0.22.0 app/assets/javascripts/decidim/forms/max_choices_alert.component.js.es6