|
@@ -27,14 +27,18 @@ export function autocomplete (inputField, path) {
|
|
|
return selectedLi;
|
|
|
}
|
|
|
|
|
|
- input.addEventListener('blur', () => {
|
|
|
+ /*input.addEventListener('blur', () => {
|
|
|
setTimeout(() => {
|
|
|
if (!clickOccured) {
|
|
|
results.hidden = true;
|
|
|
}
|
|
|
},500);
|
|
|
clickOccured = false;
|
|
|
- });
|
|
|
+ });*/
|
|
|
+
|
|
|
+ document.addEventListener('click', () => {
|
|
|
+ results.hidden = true;
|
|
|
+ })
|
|
|
|
|
|
input.addEventListener('keydown', (e) => {
|
|
|
if (e.key === 'Enter') {
|
|
@@ -70,16 +74,16 @@ export function autocomplete (inputField, path) {
|
|
|
})
|
|
|
|
|
|
const clearResults = () => {
|
|
|
- results.innerHTML = '';
|
|
|
+ results.innerText = '';
|
|
|
results.hidden = true;
|
|
|
}
|
|
|
|
|
|
input.addEventListener('input', (e) => {
|
|
|
const term = input.value.trim();
|
|
|
+ console.log(term)
|
|
|
|
|
|
if (term.length === 0) {
|
|
|
// Ne pas envoyer de requête si le champ est vide
|
|
|
- results.innerText = '';
|
|
|
clearResults();
|
|
|
return;
|
|
|
}
|
|
@@ -125,6 +129,7 @@ export function autocomplete (inputField, path) {
|
|
|
|
|
|
li.addEventListener('click', (e) => {
|
|
|
clickOccured = true;
|
|
|
+ leaveSelectedLi();
|
|
|
input.value = e.target.innerText;
|
|
|
clearResults();
|
|
|
},true)
|