Sha256: 90ae1b5f15684c51ecbfc232baaadab05f802cf821aee5a681cf313cdf6107b8

Contents?: true

Size: 1.2 KB

Versions: 34

Compression:

Stored size: 1.2 KB

Contents

((exports) => {
  class SubformTogglerComponent {
    constructor(options = {}) {
      this.controllerSelect = options.controllerSelect;
      this.subformWrapperClass = options.subformWrapperClass;
      this.globalWrapperSelector = options.globalWrapperSelector;
      this._bindEvent();
      this._runAll();
    }

    _runAll() {
      this.controllerSelect.each((idx, el) => {
        this.run(el);
      });
    }

    run(target) {
      let $target = $(target);
      let subformWrapperClass = this.subformWrapperClass;
      let value = $target.val();

      let $form = $target.parents(this.globalWrapperSelector);
      let $subforms = $form.find(`.${subformWrapperClass}`);
      let $selectedSubform = $subforms.filter(`#${subformWrapperClass}-${value}`)

      $subforms.find("input,textarea").prop("disabled", true);
      $subforms.hide();

      $selectedSubform.find("input,textarea").prop("disabled", false);
      $selectedSubform.show();
    }

    _bindEvent() {
      this.controllerSelect.on("change", (event) => {
        this.run(event.target);
      });
    }
  }

  exports.DecidimAdmin = exports.DecidimAdmin || {};
  exports.DecidimAdmin.SubformTogglerComponent = SubformTogglerComponent;
})(window);

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
decidim-admin-0.23.5 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.4 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.3 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.2 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.1.rc1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.23.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.22.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.21.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.20.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.20.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.19.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.18.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.19.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.17.2 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.18.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.17.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.16.1 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.17.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6
decidim-admin-0.16.0 app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6