diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue index 54aae4cc44826779c080e7197c49abbf4e7cf48d..e51c08c0a527e736a876c411565baf16ea1be329 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) }