2022-04-12 00:07:34 +02:00
|
|
|
const form = document.getElementById("autocomplete-form")
|
|
|
|
|
|
|
|
form.addEventListener("submit", function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
|
|
|
|
2022-04-11 23:52:19 +02:00
|
|
|
new Autocomplete('#autocomplete', {
|
|
|
|
search: input => {
|
|
|
|
const url = `/search/autocomplete/?q=${encodeURI(input)}`
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (input.length === 0) {
|
|
|
|
return resolve([])
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(url)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
resolve(data)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getResultValue: result => result.name,
|
|
|
|
onSubmit: result => {
|
|
|
|
if (!result) {
|
2022-04-12 00:07:34 +02:00
|
|
|
form.submit()
|
2022-04-11 23:52:19 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
location.href = result.url
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|