Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
m-casanova authored Oct 13, 2024
1 parent 3ca0f08 commit 0d99e2d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<div data-id="${item.io}">${item.n}<br/><span class="info"><span class="f${(db_indice[category][item.io].z == 1)?0:1}">◼</span> ${item.c} ${description}</span></div>`;
return `<div data-id="${item.io}" data-name="${item.n}">${item.n}<br/><span class="info"><span class="f${(db_indice[category][item.io].z == 1)?0:1}">◼</span> ${item.c} ${description}</span></div>`;
}).join('');
suggestionsBox.innerHTML = suggestionsHtml;
suggestionsBox.style.display = 'block';

suggestionsBox.querySelectorAll('div').forEach(div => {
div.addEventListener('click', function() {
input.value = div.innerHTML.replace(/<br>.*?$/g, '');
input.value = div.dataset.name;
suggestionsBox.style.display = 'none';
aggiorna(category, div.dataset.id);
});
Expand All @@ -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(/<br>.*?$/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(/<br>.*^$/, '');
input.value = singleSuggestion.dataset.name;
suggestionsBox.style.display = 'none';
aggiorna(category, singleSuggestion.dataset.id);
}
Expand Down

0 comments on commit 0d99e2d

Please sign in to comment.