Sha256: e336f7fe39e15f095bd0bfa7eb5349c9462d88cee87e5389ff43d153ea6ec790

Contents?: true

Size: 1.31 KB

Versions: 44

Compression:

Stored size: 1.31 KB

Contents

((exports) => {
  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();
      });
    }
  }

  exports.DecidimAdmin = exports.DecidimAdmin || {};
  exports.DecidimAdmin.FieldDependentInputsComponent = FieldDependentInputsComponent;
  exports.DecidimAdmin.createFieldDependentInputs = (options) => {
    return new FieldDependentInputsComponent(options);
  };
})(window);

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-admin-0.24.3 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.6 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.24.2 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.5 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.24.1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.24.0 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.24.0.rc2 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.4 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.24.0.rc1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.3 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.2 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.1.rc1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.23.0 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.22.0 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.21.0 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.20.1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.20.0 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.19.1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6
decidim-admin-0.18.1 app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6