From bfd21de3af12b45339ba443ecbf37ceee2f5a1ac Mon Sep 17 00:00:00 2001 From: "Henrik.Askjer" <henrik.askjer@uib.no> Date: Fri, 27 Aug 2021 11:34:13 +0200 Subject: [PATCH] Avoid dropdown when selecting by clicking --- src/components/Autocomplete.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue index 54aae4c..e51c08c 100644 --- a/src/components/Autocomplete.vue +++ b/src/components/Autocomplete.vue @@ -55,7 +55,7 @@ .then( function(response) { let currentSearch = self.$refs.autocomplete.searchInput - if (currentSearch == q) { + if (currentSearch == q & self.suggesting) { let hits = [] response.data.forEach((item, i) => { @@ -87,15 +87,20 @@ select(item) { this.items = [] if (item) { - if (typeof item === 'string') { // if blurred without selecting an option + if (typeof item == 'string') { // if blurred without selecting an option // TODO: sett timeout for å vente på siste forslag? item = {q: item, label: item} } if (item.q == this.$refs.autocomplete.searchInput) { this.$emit('submit', item) + let self = this - setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1) + setTimeout(() => { + self.$refs.autocomplete.$refs.input.select() + this.items = [] + this.suggesting = false + }, 1) } } @@ -103,6 +108,7 @@ }, methods: { run_query(q) { + this.suggesting = true this.items = [] this.debounced(q, this) } -- GitLab