The issue is that agentSearch is not a function, but it is being called as one in the template. Instead, agentSearch should be a computed property that returns the filtered agents based on the search criteria. Here's an updated version of the setup function:
export default {
setup() {
const search_agent = ref('');
const search_category = ref('');
const { agents, getAgents } = useAgents();
const { categories, getCategories } = useCategories();
onMounted(() => {
getAgents();
getCategories();
});
const filteredAgents = computed(() => {
return agents.value.filter(agent => {
const matchesCategory = !search_category.value || agent.category.id === parseInt(search_category.value);
const matchesAgent = !search_agent.value || `${agent.first_name} ${agent.last_name}`.toLowerCase().includes(search_agent.value.toLowerCase());
return matchesCategory && matchesAgent;
});
});
return { agents, getAgents, categories, search_category, search_agent, filteredAgents };
},
components: {
FooterPage,
Bootstrap4Pagination,
},
};
In the template, replace agentSearch with filteredAgents:
<form class="ps-form--agent-search" action="" method="get">
<div class="row">
<div class="col-md-5 col-12">
<div class="ps-form underline">
<input v-model="search_agent" class="form-control" type="text" placeholder="Enter agent name.." />
</div>
</div>
<div class="col-md-7">
<div class="row">
<div class="col-md-4">
<div class="ps-form select underline">
<select class="form-control">
<option>Chicago</option>
<option>New Jork</option>
<option>London</option>
</select>
<i class="lnil lnil-chevron-down"></i>
</div>
</div>
<div class="col-md-4">
<div class="ps-form select underline">
<select v-model="search_category" class="form-control">
<option value="" selected>All Categories</option>
<option v-for="category in categories" :value="category.id">{{ category.name }}</option>
</select>
<i class="lnil lnil-chevron-down"></i>
</div>
</div>
<div class="col-md-4">
<div class="ps-form__submit">
<button class="ps-btn">Search</button>
</div>
</div>
</div>
</div>
</div>
</form>
<div v-for="agent in filteredAgents" :key="agent.id">
{{ agent.first_name }} {{ agent.last_name }}
</div>