xxxxxxxxxx
1
<div class="col-4 mt-3">
2
<div class="js-kobee-autocomplete form-outline mb-4"
3
data-mdb-input-init id="searchView_keyCombobox"
4
data-kobee-autocomplete='[{"id":"", "name":""}, {"id":"1", "name":"One"},{"id":"2", "name":"Two"}]'>
5
<input type="text"
6
id="searchView_key" name="searchView.key"
7
class="form-control" />
8
<label class="form-label select-label"
9
for="searchView_key">
10
label
11
</label>
12
</div>
13
</div>
14
<input id="clickme" value="Click Me" type="button">
1
1
xxxxxxxxxx
1
var comboboxSelects = document.querySelectorAll(".js-kobee-autocomplete");
2
comboboxSelects.forEach(initAutoComplete);
3
4
function initAutoComplete(/** DomNode */ dropdown) {
5
const data = JSON.parse(dropdown.dataset.kobeeAutocomplete);
6
const dataFilter = (value) => {
7
//const reg = new RegExp(value.toLowerCase());
8
return data.filter((item) => {
9
//return reg.test((item.label ?? item.name).toLowerCase());
10
return (item.label ?? item.name).toLowerCase().startsWith(value.toLowerCase());
11
});
12
};
13
14
new mdb.Autocomplete(dropdown, {
15
filter: dataFilter,
16
displayValue: (value) => value.label ?? value.name,
17
});
18
}
19
20
let resetComponentMap = {};
21
/**
22
* We need to reset the input because the AutoComplete has no setValue event.
23
*/
24
resetComponentMap.resetAutoComplete = function(/*String*/ autoCompleteContainerId, defaultValue = '') {
25
let autocompleteContainer = document.getElementById(autoCompleteContainerId);
26
let autocompleteInput = autocompleteContainer.querySelector("input[type='text']");
27
autocompleteInput.value = defaultValue;
28
const autocomplete = mdb.Autocomplete.getInstance(autocompleteInput.parentElement);
29
autocomplete._updateLabelPosition();
30
};
31
32
document.getElementById("clickme").addEventListener("click", () => {
33
resetComponentMap.resetAutoComplete("searchView_keyCombobox");
34
});
Console errors: 0