HTML
xxxxxxxxxx
1
<form>
2
3
<!-- Button trigger modal -->
4
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal">Launch demo modal</button>
5
6
<!-- Modal -->
7
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
8
<div class="modal-dialog">
9
<div class="modal-content">
10
<div class="modal-header">
11
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
12
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
13
</div>
14
<div class="modal-body">
15
16
<div id="async" class="form-outline autocomplete">
17
<input type="text" id="form2" class="form-control" />
18
<label class="form-label" for="form2">Example label</label>
19
</div>
20
21
</div>
22
<div class="modal-footer">
23
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">Close</button>
24
<button type="button" class="btn btn-primary">Save changes</button>
25
</div>
26
</div>
27
</div>
28
</div>
29
30
</form>
31
CSS
1
1
JS
xxxxxxxxxx
1
const asyncAutocomplete = document.querySelector('#async');
2
const asyncFilter = async (query) => {
3
const url = `https://swapi.py4e.com/api/people/?search=${encodeURI(query)}`;
4
const response = await fetch(url);
5
const data = await response.json();
6
return data.results;
7
};
8
9
new mdb.Autocomplete(asyncAutocomplete, {
10
filter: asyncFilter,
11
displayValue: (value) => value.name
12
});
Console errors: 0