From 42baafd2731a6f51df4035177d66a4b29cd1ef55 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 2 Mar 2022 19:49:22 +0000 Subject: [PATCH] Invert if --- web/src/components/Autocomplete.vue | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/web/src/components/Autocomplete.vue b/web/src/components/Autocomplete.vue index b71f1fe..470c4be 100644 --- a/web/src/components/Autocomplete.vue +++ b/web/src/components/Autocomplete.vue @@ -44,22 +44,25 @@ function load(text: String) { }); }; function keypress(e: KeyboardEvent) { - if (e.key == "Enter") { - const selected = Suggestions.value[0]; - selectElement(selected); - const el = (e.target); - const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])')); - const currentIndex = inputElements.indexOf(el); - const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0]; - (nextElement).focus(); - } + if (e.key != "Enter") + return; + + const selected = Suggestions.value[0]; + selectElement(selected); + const el = (e.target); + const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])')); + const currentIndex = inputElements.indexOf(el); + const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0]; + (nextElement).focus(); }; + function selectElement(element: Suggestion) { emit('update:id', element.ID); emit('update:text', element.Name); emit('update:type', element.Type); Suggestions.value = []; }; + function select(e: MouseEvent) { const target = (e.target); const valueAttribute = target.attributes.getNamedItem("value"); @@ -69,6 +72,7 @@ function select(e: MouseEvent) { const selected = Suggestions.value.filter(x => x.ID == selectedID)[0]; selectElement(selected); }; + function clear() { emit('update:id', null); emit('update:text', SearchQuery.value);