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