Added data-datalist to select input

Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-07-22 17:12:47 +02:00
parent a2edf678e6
commit 8646cd43df
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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<HTMLInputElement>(`[name="${element.dataset.filterElement}"]`)