Sha256: 0653cc665c43bae6b3bcef3a216df24f7453e5879d1d1b84460794c968e31008

Contents?: true

Size: 1.12 KB

Versions: 44

Compression:

Stored size: 1.12 KB

Contents

/* eslint-disable require-jsdoc */
class FieldDependentInputsComponent {
  constructor(options = {}) {
    this.controllerField = options.controllerField;
    this.wrapperSelector = options.wrapperSelector;
    this.dependentFieldsSelector = options.dependentFieldsSelector;
    this.dependentInputSelector = options.dependentInputSelector;
    this.enablingCondition = options.enablingCondition;
    this._bindEvent();
    this._run();
  }

  _run() {
    const $controllerField = this.controllerField;
    const $dependentFields = $controllerField.parents(this.wrapperSelector).find(this.dependentFieldsSelector);
    const $dependentInputs = $dependentFields.find(this.dependentInputSelector);

    if (this.enablingCondition($controllerField)) {
      $dependentInputs.prop("disabled", false);
      $dependentFields.show();
    } else {
      $dependentInputs.prop("disabled", true);
      $dependentFields.hide();
    }
  }

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

export default function createFieldDependentInputs(options) {
  return new FieldDependentInputsComponent(options);
}

Version data entries

44 entries across 44 versions & 1 rubygems

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