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

Merge branch 'fix_premature_autocomplete' into 'master'

Replace blur()

See merge request spraksamlingane/beta.ordbok.uib.no!42
parents 757c0111 245b59b1
No related branches found
No related tags found
No related merge requests found
...@@ -50,33 +50,35 @@ ...@@ -50,33 +50,35 @@
return axios.get(self.endpoint + 'suggest?q=' + encodeURIComponent(q)) return axios.get(self.endpoint + 'suggest?q=' + encodeURIComponent(q))
.then( .then(
function(response) { function(response) {
let hits = [] if (self.loading) {
if (q == self.search) { let hits = []
response.data.forEach((item, i) => { if (q == self.search) {
let match = encodeURIComponent(item.match) response.data.forEach((item, i) => {
let match = encodeURIComponent(item.match)
if (! hits[0] || hits[0].word != match) { if (! hits[0] || hits[0].word != match) {
hits.splice(0, 0, {q: encodeURIComponent(q), lang_set: new Set(), word: match, articles: []}) hits.splice(0, 0, {q: encodeURIComponent(q), lang_set: new Set(), word: match, articles: []})
} }
hits[0].lang_set.add(item.dictionary == 'bob' ? 'bm' : 'nn') hits[0].lang_set.add(item.dictionary == 'bob' ? 'bm' : 'nn')
hits[0].articles.push(item) hits[0].articles.push(item)
}); });
hits.forEach(function (hit) { hits.forEach(function (hit) {
if (hit.lang_set) { if (hit.lang_set) {
hit.label = decodeURIComponent(hit.word) hit.label = decodeURIComponent(hit.word)
} }
}); });
hits.reverse() hits.reverse()
hits = hits.slice(0, 9) hits = hits.slice(0, 9)
} }
hits.sort( (h1, h2) => { hits.sort( (h1, h2) => {
let val1 = h1.label.length * 10 + (h1.label[0].toLowerCase() === h1.label[0] ? 0 : 1) let val1 = h1.label.length * 10 + (h1.label[0].toLowerCase() === h1.label[0] ? 0 : 1)
let val2 = h2.label.length * 10 + (h2.label[0].toLowerCase() === h2.label[0] ? 0 : 1) let val2 = h2.label.length * 10 + (h2.label[0].toLowerCase() === h2.label[0] ? 0 : 1)
return val1 - val2 return val1 - val2
}) })
self.items = hits self.items = hits
self.loading = false self.loading = false
}
}) })
}, 100) }, 100)
} }
...@@ -90,13 +92,15 @@ ...@@ -90,13 +92,15 @@
} }
}, },
select(item) { select(item) {
if (typeof item === 'string') { if (item) {
item = {"q": encodeURIComponent(item)} if (typeof item === 'string') {
item = {"q": encodeURIComponent(item)}
}
this.loading = false
this.$emit('submit', item)
let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
} }
this.$emit('submit', item)
this.$refs.autocomplete.blur()
let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
} }
}, },
methods: { methods: {
......
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