Sha256: 5c6e93e27de5651bbe5e08dcd4cf37230d300cc5ca76a08d8e604dfd50a42b88

Contents?: true

Size: 1.02 KB

Versions: 44

Compression:

Stored size: 1.02 KB

Contents

export default 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,select").prop("disabled", true);
    $subforms.hide();

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

  _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.25.0.rc4 app/packs/src/decidim/admin/subform_toggler.component.js
decidim-admin-0.25.0.rc3 app/packs/src/decidim/admin/subform_toggler.component.js
decidim-admin-0.25.0.rc2 app/packs/src/decidim/admin/subform_toggler.component.js
decidim-admin-0.25.0.rc1 app/packs/src/decidim/admin/subform_toggler.component.js