Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
VOTE-550 Improve state selector search
Browse files Browse the repository at this point in the history
  • Loading branch information
rayestrada committed Nov 27, 2023
1 parent c72c4ab commit 4aa545f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions assets/scripts/state-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@

// Filter dropdown results based on user input.
function stateListFilter() {
let filter, txtValue;
let filter, txtValue, wordTxtValues, keyValue;
filter = stateInput.value.toUpperCase();
txtValue = "";
wordTxtValues = [];
keyValue = "";
stateListResults = [];

for (let i = 0; i < stateFilteredOptions.length; i++) {
let li = stateFilteredOptions[i].parentNode;
txtValue = li.textContent || li.innerText;
txtValue = li.textContent.trim() || li.innerText.trim();
wordTxtValues = txtValue.split(' ');
keyValue = li.firstElementChild.getAttribute('key');

if (txtValue.toUpperCase().indexOf(filter) > -1) {
// Match user input with the start of the state name or state abbrev.
if (wordTxtValues.some((elem) => elem.length > 2 && elem.toUpperCase().startsWith(filter))
|| (filter.length === 2 && keyValue.toUpperCase() === filter)) {
li.removeAttribute('hidden');
stateListResults.push(stateFilteredOptions[i]);
} else {
Expand Down

0 comments on commit 4aa545f

Please sign in to comment.