Context
Currently, I am dealing with a situation where I am passing an array of objects to a material autocomplete feature. The documentation for this can be found here.
However, upon selecting an item from the list for the first time, it throws an error. Strangely enough, if I click on the item again, it eventually selects it as expected. This strange behavior seems to repeat every time I interact with the autocomplete items.
Error Illustration
[Vue warn]: Error in event handler for "input": "TypeError: Cannot read property 'constructor' of undefined"
Sample Code Snippet
<template>
<md-autocomplete
v-model="customer"
:md-options="customers"
@md-changed="getCustomers"
@md-opened="getCustomers"
@md-selected="getSelected"
>
</md-autocomplete>
</template>
<script>
data: () => ({
customers: [],
customer: "", // I also tried making this a {}
}),
methods: {
getCustomers(searchTerm) {
this.customers = new Promise(resolve => {
if (!searchTerm) {
resolve(this.GET_CUSTOMERS);
} else {
const term = searchTerm.toLowerCase();
this.customers = this.GET_CUSTOMERS.filter(({ email }) => {
email.toLowerCase().includes(term);
});
resolve(this.customers);
}
});
},
getSelected() {
console.log(this.customer);
},
}
</script>
Data Example
GET_CUSOTMERS: [
{ client_id: 1, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73160b121e031f1633160b121e031f165d101c1e">[email protected]</a>" },
{ client_id: 2, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="67021f060a170b0227021f060a170b024904080a">[email protected]</a>" }
];
Inquiry
I'm currently facing an error message and would like some advice on how to fix it. Does anyone know what this error indicates? I've heard about similar bugs in Angular's autocomplete feature using Material, but I believe there might be a solution specific to Vue Material. Your insights are greatly appreciated.