Skip to content
Snippets Groups Projects
Commit 88b3cc0a authored by Henrik Askjer's avatar Henrik Askjer
Browse files

New solution to autocorrect issue

parent dc5ea279
No related branches found
No related tags found
No related merge requests found
...@@ -54,22 +54,23 @@ ...@@ -54,22 +54,23 @@
n: 9}} ) n: 9}} )
.then( .then(
function(response) { function(response) {
if (self.suggesting) { let currentSearch = self.$refs.autocomplete.searchInput
let hits = [] if (currentSearch == q) {
response.data.forEach((item, i) => {
let hit = {q: q, label: item[0]}
hit.lang = item[1][1] ? "bm, nn" : {"bob": "bm", "nob": "nn"}[item[1][0]]
hits.push(hit)
}); let hits = []
response.data.forEach((item, i) => {
let hit = {q: q, label: item[0]}
hit.lang = item[1][1] ? "bm, nn" : {"bob": "bm", "nob": "nn"}[item[1][0]]
hits.push(hit)
self.items = hits });
hits.push({q: currentSearch, label: currentSearch})
self.items = hits
}
// Fritekstsøk
let currentSearch = self.$refs.autocomplete.searchInput
self.items.push({q: currentSearch, label: currentSearch + ' '})
}
self.loading = false self.loading = false
}) })
}, 100) }, 100)
...@@ -84,23 +85,25 @@ ...@@ -84,23 +85,25 @@
} }
}, },
select(item) { select(item) {
this.items = []
if (item) { if (item) {
if (item.q === this.$refs.autocomplete.searchInput) { if (typeof item === 'string') { // if blurred without selecting an option
this.items = [] // TODO: sett timeout for å vente på siste forslag?
this.suggesting = false item = {q: item}
}
if (item.q == this.$refs.autocomplete.searchInput) {
this.$emit('submit', item) this.$emit('submit', item)
let self = this let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1) setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
} }
// TODO: else: sett timeout for å vente på siste forslag
} }
} }
}, },
methods: { methods: {
run_query(q) { run_query(q) {
this.suggesting = true this.items = []
this.debounced(q, this) this.debounced(q, this)
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment