Disable server-side autocompletion when acSource is not set

This commit is contained in:
KoloMl 2024-06-03 17:48:42 +04:00
parent f84e358eec
commit 8d2c082413

View file

@ -171,6 +171,8 @@ function showAutocomplete(suggestions, fetchedTerm, targetInput) {
}
function getSuggestions(term) {
// In case source URL was not given at all, do not try sending the request.
if (!inputField.dataset.acSource) return [];
return fetch(`${inputField.dataset.acSource}${term}`).then(response => response.json());
}
@ -241,9 +243,9 @@ function listenAutocomplete() {
originalTerm = inputField.value;
const fetchedTerm = inputField.value;
const {ac, acMinLength} = inputField.dataset;
const {ac, acMinLength, acSource} = inputField.dataset;
if (ac && (fetchedTerm.length >= acMinLength)) {
if (ac && acSource && (fetchedTerm.length >= acMinLength)) {
if (cache[fetchedTerm]) {
showAutocomplete(cache[fetchedTerm], fetchedTerm, event.target);
}