HTML
xxxxxxxxxx
1
<div id="basic" class="form-outline" data-mdb-input-init>
2
<input id="testId" type="text" name="" class="form-control input_small recipe_process_ingredient_name" placeholder="Recipe" >
3
</div>
4
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous"></script>
CSS
1
1
JS
xxxxxxxxxx
1
$(document).on("keyup",".recipe_process_ingredient_name",function(){
2
console.log('d')
3
const $input = $(this);
4
const asyncFilter = async (query) => {
5
const url = `https://swapi.py4e.com/api/people/?search=${encodeURI(query)}`;
6
const response = await fetch(url);
7
const data = await response.json();
8
return data.results;
9
};
10
11
// I applied the same way you suggested but when i console the element it gives... check log
12
console.log($input.parent().get(0));
13
14
// while in my case its giving
15
// <div class="form-outline" data-mdb-input-init="">
16
// <input type="text" name="" class="form-control input_small recipe_process_ingredient_name active autocomplete-input" placeholder="Recipe" role="combobox" aria-expanded="false" aria-owns="autocomplete-dropdown-248083" aria-haspopup="true" autocomplete="off">
17
// <div class="autocomplete-loader spinner-border" role="status">
18
// <span class="sr-only">Loading...</span>
19
// </div>
20
// </div>
21
22
mdb.Autocomplete.getOrCreateInstance($input.parent().get(0), {
23
filter: asyncFilter,
24
displayValue: (value) => value.name
25
});
26
});
Console errors: 0