mirror of
https://github.com/Findus23/RPGnotes.git
synced 2024-09-19 15:43:45 +02:00
25 lines
597 B
JavaScript
25 lines
597 B
JavaScript
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) {
|
|
return
|
|
}
|
|
location.href = result.url
|
|
}
|
|
|
|
})
|