diff --git a/src/layouts/insurance-company/insurance-company-question.vue b/src/layouts/insurance-company/insurance-company-question.vue index 378d4f4b5..ecbb6876d 100644 --- a/src/layouts/insurance-company/insurance-company-question.vue +++ b/src/layouts/insurance-company/insurance-company-question.vue @@ -96,15 +96,29 @@ export default { findMatches(request, response) { const matches = []; const term = request?.term?.toUpperCase(); + const nonPriorityMatches = []; + this.searchableInsuranceCompanyList.forEach((company, index) => { if ( - company.accountName.indexOf(term) !== -1 || - company.altTerms.indexOf(term) !== -1 + company.accountName.toUpperCase().indexOf(term) !== -1 || + company.altTerms.toUpperCase().indexOf(term) !== -1 ) { matches.push(company.accountName); } }); - response(matches); + + // Prioritize matched typed entries to top of list + const priorityMatches = matches.filter((companyName, index) => { + if (companyName.toUpperCase().indexOf(term) === 0) { + return companyName; + } else { + nonPriorityMatches.push(companyName); + } + }); + + const prioritizedMatches = [...priorityMatches, ...nonPriorityMatches]; + + response(prioritizedMatches); }, selectInsuranceCompany(parentAccountName) { // this runs upon user selection within jQueryUI Autocomplete