diff --git a/assets/js/script.js b/assets/js/script.js index 91cca17..6e32feb 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -328,14 +328,14 @@ function impostaRicerca(category) { if (risultati.length > 0) { const suggestionsHtml = risultati.map(item => { const description = category === 1 ? 'Comune' : dizTipo[item.t]; - return `
${item.n}
${item.c} ${description}
`; + return `
${item.n}
${item.c} ${description}
`; }).join(''); suggestionsBox.innerHTML = suggestionsHtml; suggestionsBox.style.display = 'block'; suggestionsBox.querySelectorAll('div').forEach(div => { div.addEventListener('click', function() { - input.value = div.innerHTML.replace(/
.*?$/g, ''); + input.value = div.dataset.name; suggestionsBox.style.display = 'none'; aggiorna(category, div.dataset.id); }); @@ -356,12 +356,12 @@ function impostaRicerca(category) { } else if (e.key === 'ArrowUp') { newActive = active ? active.previousElementSibling : suggestionsBox.lastElementChild; } else if (e.key === 'Enter' && active) { - input.value = active.innerHTML.replace(/
.*?$/g, ''); + input.value = active.dataset.name; suggestionsBox.style.display = 'none'; aggiorna(category, active.dataset.id); } else if (e.key === 'Enter' && suggestionsBox.childElementCount === 1) { const singleSuggestion = suggestionsBox.firstElementChild; - input.value = singleSuggestion.innerHTML.replace(/
.*^$/, ''); + input.value = singleSuggestion.dataset.name; suggestionsBox.style.display = 'none'; aggiorna(category, singleSuggestion.dataset.id); }