xxxxxxxxxx
1
<div id="async" class="form-outline autocomplete">
2
<input type="text" id="form2" class="form-control" />
3
<label class="form-label" for="form2">Example label</label>
4
</div>
1
1
xxxxxxxxxx
1
const asyncAutocomplete = document.querySelector('#async');
2
const asyncFilter = async (query) => {
3
try {
4
const url = `https://swapi.py4e.comxyz/api/people/?search=${encodeURI(query)}`;
5
const response = await fetch(url);
6
const data = await response.json();
7
return data.results;
8
} catch (error) {
9
console.error('Error occured:', error);
10
}
11
};
12
13
14
15
new mdb.Autocomplete(asyncAutocomplete, {
16
filter: asyncFilter,
17
displayValue: (value) => value.name
18
});
19
20
Console errors: 0