From 2e615142ad55195554d77f9c5993111200ec14e2 Mon Sep 17 00:00:00 2001 From: OvidiuAl3x Date: Thu, 18 Apr 2024 15:19:55 +0300 Subject: [PATCH 1/2] Added feature: Now able to search data without hyphens and return the correct data. --- script.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index aa9c160..c08a85a 100644 --- a/script.js +++ b/script.js @@ -496,6 +496,8 @@ function performSearch(data) { for (const location of locations) { const judetName = location.nume ? location.nume : parentJudetName; + + const queryForComparison = query.replace(/\s/g, "-"); const filtre = judetName .toLowerCase() @@ -504,7 +506,16 @@ function performSearch(data) { .replace(cREG, "a") .replace(dREG, "a") .replace(eREG, "i") - .includes(query) || judetName.toLowerCase().includes(query); + .includes(query) || + judetName.toLowerCase().includes(query) || + judetName + .toLowerCase() + .replace(aREG, "s") + .replace(bREG, "t") + .replace(cREG, "a") + .replace(dREG, "a") + .replace(eREG, "i") + .includes(queryForComparison.toLowerCase()); if (filtre) { const result = { From f600027606ada2cc49f0e834ef95e37a60c722ab Mon Sep 17 00:00:00 2001 From: OvidiuAl3x Date: Thu, 18 Apr 2024 15:32:46 +0300 Subject: [PATCH 2/2] Correction of data display in dropd-down --- script.js | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/script.js b/script.js index c08a85a..036a27d 100644 --- a/script.js +++ b/script.js @@ -142,12 +142,11 @@ function renderDropdown(data) { function renderLocationDetails(selectedItem) { const totJudetul = document.createElement("div"); totJudetul.classList.add("tot-judetul"); - totJudetul.innerHTML = `

${selectedItem.nume.toLowerCase()}

Tot județul`; + totJudetul.innerHTML = `

${selectedItem.nume}

Tot județul`; dropDownContainer.appendChild(totJudetul); totJudetul.addEventListener("click", function () { dropDownContainer.classList.remove("searchResults-display"); - searchInput.value = selectedItem.nume.toLowerCase(); - searchInput.style.textTransform = "capitalize"; + searchInput.value = selectedItem.nume; }); } @@ -162,42 +161,19 @@ function renderDropdown(data) { const uniqueArray = Array.from(resultArray); uniqueArray.sort((a, b) => a.localeCompare(b)); uniqueArray.forEach((item) => { - const keywordsToCheck = ["de", "lui", "cu", "din", "cel", "la", "II"]; - const keywordMatchQuery = keywordsToCheck.some((keyword) => - item.includes(keyword) - ); - const card = dropDownTemplate.content.cloneNode(true).children[0]; const dataJudet = card.querySelector("[dropDown-afisare]"); - dataJudet.innerHTML = keywordMatchQuery ? item : item.toLowerCase(); - dataJudet.style.textTransform = !keywordMatchQuery ? "capitalize" : ""; + dataJudet.innerHTML = item; + // show results in input card.addEventListener("click", () => { - function capitalizeFirstLetter(str) { - return str - .split(/([\s-]+)/) - .map((part) => { - if (part.trim() === "-") { - return part; // Preserve hyphens - } else { - return ( - part.charAt(0).toUpperCase() + part.slice(1).toLowerCase() - ); - } - }) - .join(""); - } - - const resultJudet = selectedItem.nume.toLowerCase(); - const capitalizedJudet = capitalizeFirstLetter(resultJudet); + const resultJudet = selectedItem.nume; dropDownContainer.classList.remove("searchResults-display"); - searchInput.value = `${ - keywordMatchQuery ? item : item.toLowerCase() - }, ${capitalizedJudet}`; - searchInput.style.textTransform = !keywordMatchQuery - ? "capitalize" - : ""; + searchInput.value = `${item}, ${resultJudet}`; + + const inputWidth = searchInput.value.length * 9; + searchInput.style.width = `${inputWidth}px`; }); dropDownContainer.appendChild(card); @@ -216,8 +192,7 @@ function renderDropdown(data) { const card = dropDownTemplate.content.cloneNode(true).children[0]; const dataJudet = card.querySelector("[dropDown-afisare]"); const dropDownImage = card.querySelector("[dropDown-image]"); - dataJudet.innerHTML = item.nume.toLowerCase(); - dataJudet.style.textTransform = "capitalize"; + dataJudet.innerHTML = item.nume; dropDownImage.src = "./icons/right-arrow.png"; dropDownImage.alt = "arrow-icon"; dropDownContainer.appendChild(card);