Sha256: b46b597408e53fcfdbd3e0aa5ee3862554c009eeec8b980fc274ce4b0e3fec9c

Contents?: true

Size: 1.03 KB

Versions: 44

Compression:

Stored size: 1.03 KB

Contents

export default class SubformMultiTogglerComponent {
  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 $selectedSubform = $form.find(`#${subformWrapperClass}-${value}`)

    if ($target.prop("checked")) {
      $selectedSubform.find("input,textarea,select").prop("disabled", false);
      $selectedSubform.show();
    } else {
      $selectedSubform.find("input,textarea,select").prop("disabled", true);
      $selectedSubform.hide();
    }
  }

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.4 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.27.9 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.29.0 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.3 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.27.8 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.29.0.rc4 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.29.0.rc3 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.29.0.rc2 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.29.0.rc1 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.2 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.27.7 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.1 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.27.6 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.26.10 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.26.9 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.0 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.27.5 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.0.rc5 app/packs/src/decidim/admin/subform_multi_toggler.component.js
decidim-admin-0.28.0.rc4 app/packs/src/decidim/admin/subform_multi_toggler.component.js