From 8646cd43df8c64c55a78b4e1228146629b5cba12 Mon Sep 17 00:00:00 2001 From: Florian Bouillon Date: Wed, 22 Jul 2020 17:12:47 +0200 Subject: [PATCH] Added data-datalist to select input Signed-off-by: Florian Bouillon --- src/modules/RepeatInput.ts | 6 +++++- src/modules/SelectInput.ts | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/modules/RepeatInput.ts b/src/modules/RepeatInput.ts index 4d609d3..0db6fb9 100644 --- a/src/modules/RepeatInput.ts +++ b/src/modules/RepeatInput.ts @@ -129,7 +129,7 @@ export default class RepeatInput extends DefaultInput { if (this.element.querySelectorAll(".fmr-element").length <= index) { //add element - if ((el as any) == "") continue + if (!el) continue this.addLine(el) continue } @@ -160,6 +160,10 @@ export default class RepeatInput extends DefaultInput { } public verify(): boolean { + console.log(this.elements.length) + if (this.element.hasAttribute('required') && this.elements.length === 0) { + return false + } for (const el of this.elements) { for (const i of el) { if (!i.verify()) return false diff --git a/src/modules/SelectInput.ts b/src/modules/SelectInput.ts index df8d65a..b20526c 100644 --- a/src/modules/SelectInput.ts +++ b/src/modules/SelectInput.ts @@ -4,9 +4,23 @@ import { realType } from '../Functions'; import FormManager from '../FormManager'; export default class SelectInput extends DefaultInput { - + public constructor(element: HTMLSelectElement, form: FormManager) { super(element, form) + if (element.hasAttribute('data-datalist')) { + const datalist = document.querySelector(`#${element.dataset.datalist}`) + if (!datalist) { + console.warn('Error, Datalist does not exist') + } else { + for (const child of element.children) { + !(child as HTMLElement).hasAttribute('disabled') && child.remove() + } + for (const child of datalist.children) { + // console.log(child.value) + element.appendChild(child.cloneNode(true)) + } + } + } if (element.dataset.filterElement) { const options = element.querySelectorAll('option') const el = form.form.querySelector(`[name="${element.dataset.filterElement}"]`)