WIP insurance search autocomplete.

Add backspace show list feature
Add bold matched letters
This commit is contained in:
Bryan Mauger 2024-02-19 17:13:24 -05:00
parent 3578401a95
commit e8f4f7bfd4

View file

@ -93,12 +93,6 @@ export default {
vm.setCmsContent(resultMap.cmsContent); vm.setCmsContent(resultMap.cmsContent);
}); });
}, },
data() {
return {
availableTags: ["Allstate", "Liberty Mutual", "State Farm", "Farmers", "Progressive"],
selectedQuery: "",
};
},
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.carId !== null; return store.getters.vehicle.carId !== null;
@ -112,19 +106,52 @@ export default {
forwardButtonAction() { forwardButtonAction() {
alert("Still needs to be wired up"); alert("Still needs to be wired up");
}, },
}, },
mounted() { mounted() {
const select = this.handleAutocompleteSelect; const select = this.handleAutocompleteSelect;
// Temporary list of insurance companies for testing
var tags = [
"21st Century Insurance",
"Farmers Insurance",
"Grange Insurance",
"Liberty Mutual Insurance",
"State Auto Insurance",
"State Farm Insurance",
"Travelers Insurance"
];
$("#autocomplete").autocomplete({ $("#autocomplete").autocomplete({
source: this.availableTags, source: function( request, response ) {
position: { var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
my: 'left top+6', response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}, },
select: function( event, ui ) { position: {
my: "left top+6",
},
minLength: 0,
select: function (event, ui) {
select(ui.item.value); select(ui.item.value);
} },
search: function(event, ui) {
setTimeout(() => {
let w = $(this).autocomplete("widget").find("div"),
re = new RegExp("("+this.value+")", "i");
w.html((i, html) =>
html.replace(re, "<b>$1</b>")
);
},5);
},
}); });
}, },
watch: {
selectedQuery(newValue, oldValue) {
if (oldValue.length > 0 && newValue.length === 0) {
$( "#autocomplete" ).autocomplete( "search", "" );
}
},
},
components: { components: {
funnelHeader, funnelHeader,
navbar, navbar,
@ -144,9 +171,9 @@ ul {
padding: 0; padding: 0;
background: $white; background: $white;
border: 1px solid $gray; border: 1px solid $gray;
border-radius: .25rem; border-radius: 0.25rem;
li { li {
padding: .125rem .5rem; padding: 0.125rem 0.5rem;
&:hover { &:hover {
background-color: $gray-100; background-color: $gray-100;
cursor: pointer; cursor: pointer;