1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/static/js/autocomplete.js

26 lines
597 B
JavaScript
Raw Normal View History

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) {
return
}
location.href = result.url
}
})