How to keep popup of Quasar Select component open? #12628
-
I've got a more in-depth StackOverflow question over here but wanted to post here as well since it's a more specific community. Essentially I'm populating a q-select options via an API call, attempting to allow the user to search for their address. I'm very close to finishing it, however the one remaining issue is an odd quirk (again, described more in-depth in the SO post). The gist is that after performing a search, the options are populated correctly, but the popup doesn't display. If I click on the chevron twice, the popup opens and displays all of the options. What could be the issue here, and why isn't programmatically opening it via the <template>
<q-select
ref="geolocateRef"
v-model="state.location"
:options="state.locations"
:loading="state.loadingResults"
clear-icon="clear"
dropdown-icon="expand_more"
clearable
outlined
:use-input="!state.location"
dense
label="Location (optional)"
@clear="state.locations = undefined"
@input-value="fetchOptions">
<template #prepend>
<q-icon name="place " />
</template>
<template #no-option>
<q-item>
<q-item-section class="text-grey">
No results
</q-item-section>
</q-item>
</template>
</q-select>
</template>
<script lang='ts' setup>
import { reactive } from 'vue';
import { debounce, QSelect } from 'quasar';
import { fetchGeocodeResults } from '@/services';
const state = reactive({
location: undefined as string | undefined,
locations: undefined,
loadingResults: false,
geolocateRef: null as QSelect | null,
});
const fetchOptions = debounce(async (value: string) => {
if (value) {
state.loadingResults = true;
const results = await fetchGeocodeResults(value);
state.locations = results.items.map(item => ({
label: item.title,
value: JSON.stringify(item.position),
}));
state.loadingResults = false;
state.geolocateRef?.showPopup(); // doesn't work?
}
}, 500);
</script> |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It is hard to understand the behavior without actually having it on our hands. Please share a repro using one of: If your service logic needs a private/local server, then mock it up by wrapping it in a promise that resolves on setTimeout, just like in Quasar docs on server-side related examples. |
Beta Was this translation helpful? Give feedback.
-
@jimmiejackson414 convert your QSelect template ref into a https://codesandbox.io/s/relaxed-wilson-zdhpqn?file=/src/pages/Index.vue IMO, using |
Beta Was this translation helpful? Give feedback.
@jimmiejackson414 convert your QSelect template ref into a
ref
either usingtoRefs
or just take it out of your state object and declare it as a ref, you also need to call QSelect'srefresh
method after you populated your options array.https://codesandbox.io/s/relaxed-wilson-zdhpqn?file=/src/pages/Index.vue
IMO, using
@filter
event could be more appropriate here, and the things you are doing with handling loading states, refreshing, debouncing input etc... are mostly done ootb already. see https://codepen.io/metalsadman/pen/wvPQZZV.