Created
April 27, 2018 06:47
-
-
Save simonw/8af1edd6c5c408dc33e963c7f30b286d to your computer and use it in GitHub Desktop.
Awesomplete ajax example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="http://leaverou.github.io/awesomplete/awesomplete.css"> | |
<script src="http://leaverou.github.io/awesomplete/awesomplete.js"></script> | |
<script> | |
document.addEventListener('DOMContentLoaded', () => { | |
const input = document.querySelector('input.blah'); | |
const awesomplete = new Awesomplete(input); | |
input.addEventListener("awesomplete-selectcomplete", (ev) => console.log(ev.text)); | |
input.addEventListener('keyup', (e) => { | |
var code = (e.keyCode || e.which); | |
if (code === 37 || code === 38 || code === 39 || code === 40 || code === 27 || code === 13) { | |
return; | |
} else { | |
const murl = 'http://127.0.0.1:8044/MetObjects-00f9d76/Artist+Alpha+Sort.jsono?_search='+input.value + '*'; | |
fetch(murl).then(r => r.json()).then(d => { | |
awesomplete.list = d.rows.map(row => ({value: row.id, label: row.value})); | |
}); | |
} | |
}); | |
}); | |
</script> | |
<input class="blah" style="width: 400px"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import Awesomplete from 'awesomplete';