diff --git a/src/attributes/IgnoreAttribute.ts b/src/attributes/IgnoreAttribute.ts index ec77f02..45e833d 100644 --- a/src/attributes/IgnoreAttribute.ts +++ b/src/attributes/IgnoreAttribute.ts @@ -36,6 +36,5 @@ extends AbstractAttribute { public static identity: AttributeIdentity = { attribute: IgnoreAttribute, dataElement: "data-ignore" - } } diff --git a/src/modules/SelectInput.ts b/src/modules/SelectInput.ts index fb6c71e..df8d65a 100644 --- a/src/modules/SelectInput.ts +++ b/src/modules/SelectInput.ts @@ -1,14 +1,36 @@ import InputIdentity from './Interfaces/InputIdentity'; import DefaultInput from './DefaultInput'; import { realType } from '../Functions'; +import FormManager from '../FormManager'; -/** - * - * @class FMDateInput - * @extends {FMInput} - */ export default class SelectInput extends DefaultInput { + public constructor(element: HTMLSelectElement, form: FormManager) { + super(element, form) + if (element.dataset.filterElement) { + const options = element.querySelectorAll('option') + const el = form.form.querySelector(`[name="${element.dataset.filterElement}"]`) + if (!el) { + console.warn(`Select Input has filter Attr but can't find the element (${element.dataset.filterElement})`) + } else { + const fn = () => { + options.forEach((opt) => { + if (opt.dataset.filter === el.value || opt.dataset.filter === undefined) { + opt.removeAttribute('style') + } else { + opt.style.display = 'none' + if (this.formatValue(opt.value) === this.getValue()) { + this.setValue(undefined) + } + } + }) + } + el.addEventListener('change', fn) + fn() + } + } + } + public setValue(value: any) { this.element.value = this.formatValue(value) } @@ -25,7 +47,7 @@ export default class SelectInput extends DefaultInput { } public static identity: InputIdentity = { - input: SelectInput, + input: SelectInput as any, tagName: "select" } }