Pārlūkot izejas kodu

Petite correction champs disabled quand existant

Sangfroid 8 mēneši atpakaļ
vecāks
revīzija
3cb385e9a6
2 mainītis faili ar 10 papildinājumiem un 4 dzēšanām
  1. 1 0
      assets/js/addCollectionVanilla.js
  2. 9 4
      assets/js/autocomplete.js

+ 1 - 0
assets/js/addCollectionVanilla.js

@@ -4,6 +4,7 @@ import { autocomplete } from './autocomplete'
     document
         .querySelectorAll('ul.collection-form li')
         .forEach(item => {
+            item.querySelector('input').disabled = true
             addDeleteLink(item)
         });
 

+ 9 - 4
assets/js/autocomplete.js

@@ -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)