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

VOTE-550 Improve state selector search #940

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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