Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Forked from simonw/awesomplete-ajax.html
Created June 19, 2018 18:41
Show Gist options
  • Save gregorynicholas/55af68d1a4d9be5cf543ce762106c6ea to your computer and use it in GitHub Desktop.
Save gregorynicholas/55af68d1a4d9be5cf543ce762106c6ea to your computer and use it in GitHub Desktop.
Awesomplete ajax example.
<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