From 8d2c0824133ad13fc02418b9aa1a25cfa6c52bd5 Mon Sep 17 00:00:00 2001 From: KoloMl Date: Mon, 3 Jun 2024 17:48:42 +0400 Subject: [PATCH] Disable server-side autocompletion when `acSource` is not set --- assets/js/autocomplete.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/js/autocomplete.js b/assets/js/autocomplete.js index 978c7cab..758754dd 100644 --- a/assets/js/autocomplete.js +++ b/assets/js/autocomplete.js @@ -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); }