Commit 7f2ba663 authored by JC Brand's avatar JC Brand

autocomplete: Use Array functions

parent 0a82a177
...@@ -184,21 +184,16 @@ export class AutoComplete { ...@@ -184,21 +184,16 @@ export class AutoComplete {
} else if (typeof list === "string" && list.includes(",")) { } else if (typeof list === "string" && list.includes(",")) {
this._list = list.split(/\s*,\s*/); this._list = list.split(/\s*,\s*/);
} else { // Element or CSS selector } else { // Element or CSS selector
list = helpers.getElement(list); const children = helpers.getElement(list)?.children || [];
if (list && list.children) { this._list = Array.from(children)
const items = []; .filter(el => !el.disabled)
Array.prototype.slice.apply(list.children).forEach(function (el) { .map(el => {
if (!el.disabled) { const text = el.textContent.trim();
const text = el.textContent.trim(), const value = el.value || text;
value = el.value || text, const label = el.label || text;
label = el.label || text; return (value !== "") ? { label, value } : null;
if (value !== "") { })
items.push({ label: label, value: value }); .filter(i => i);
}
}
});
this._list = items;
}
} }
if (document.activeElement === this.input) { if (document.activeElement === this.input) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment