diff --git a/web/src/components/Autocomplete.vue b/web/src/components/Autocomplete.vue index 5568a60..470c4be 100644 --- a/web/src/components/Autocomplete.vue +++ b/web/src/components/Autocomplete.vue @@ -2,6 +2,7 @@ import { ref, watch } from "vue" import { GET } from "../api"; import { useBudgetsStore } from "../stores/budget"; +import Input from "./Input.vue"; export interface Suggestion { ID: string @@ -43,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"); @@ -68,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); @@ -77,14 +82,15 @@ function clear() {