From a9eb597d5bf1d0982142e1ccec72c76f59c3192e Mon Sep 17 00:00:00 2001 From: lainvineyard Date: Mon, 12 Dec 2022 16:05:16 -0800 Subject: [PATCH] use a set to keep track of state abbreviations so that the correct ccz ID is used for locations in states like NAY and JAL in VNMLS this avoids having to rely on a hardcoded list of state abbreviations --- src/js/idx-omnibar.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/js/idx-omnibar.js b/src/js/idx-omnibar.js index b4cbf61e2..5ae43bc83 100644 --- a/src/js/idx-omnibar.js +++ b/src/js/idx-omnibar.js @@ -45,8 +45,20 @@ var idxOmnibar = function(jsonData){ } return displayName; }; + + let includedStateAbreviations = new Set(); + //helper function for grabbing the name of each item in JSON creating new array var createArrays = function(array, newArray, type, fieldName){ + + // Add state abbreviations to the set for later reference + array.forEach((item) => { + if (item.stateAbrv) { + console.log(item.stateAbrv); + includedStateAbreviations.add(item.stateAbrv); + } + }); + //if zip, do not append state abbreviations if(type === 'zip'){ array.forEach(function(item){ @@ -54,6 +66,8 @@ var idxOmnibar = function(jsonData){ if(item.name !== '' && item.name !== 'Other' && item.name !== 'Other State'){ newArray.push(item.name); } + + }); //if county, append County and State } else if(type ==='county') { @@ -479,7 +493,11 @@ var idxOmnibar = function(jsonData){ } for(var i=0; i < list.length; i++){ //filter out blank and county from input and check for appended state - if (inputFiltered.split(' county')[0] === list[i].name.toLowerCase() && whatState(input.value.split(', ')[1], list[i].stateAbrv, stateException) && isCounty(inputFiltered.split(' county')[1], listType) && input.value) { + if (inputFiltered.split(' county')[0] === list[i].name.toLowerCase() + && ( + whatState(input.value.split(', ')[1], list[i].stateAbrv, stateException) + || includedStateAbreviations.has(input.value.split(', ')[1].toUpperCase())) + && isCounty(inputFiltered.split(' county')[1], listType) && input.value) { switch(listType){ case 'cities': foundResult = true;