Skip to content

Commit a8d8535

Browse files
committed
feat(primeAutoComplete): enable async complete functions with loading state, add additional properties (minLength, placeholder, fluid)
1 parent 6254879 commit a8d8535

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/components/PrimeAutoComplete.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface FormKitPrimeAutoCompleteProps {
1616
optionLabel?: AutoCompleteProps['optionLabel']
1717
options?: any[] | undefined
1818
size?: AutoCompleteProps['size']
19+
minLength?: AutoCompleteProps['minLength']
20+
placeholder?: AutoCompleteProps['placeholder']
21+
fluid?: AutoCompleteProps['fluid']
1922
}
2023
2124
const props = defineProps({
@@ -29,15 +32,26 @@ const { validSlotNames, unstyled, isInvalid, handleInput, handleBlur } = useForm
2932
3033
const suggestions = ref(['', {}])
3134
suggestions.value = []
35+
const loading = ref(false)
3236
33-
function search(event: AutoCompleteCompleteEvent) {
37+
async function search(event: AutoCompleteCompleteEvent) {
3438
if (props.context?.options && props.context?.optionLabel) {
3539
suggestions.value = props.context.options.filter((option) => {
3640
return option[`${props.context.optionLabel}`].toString().toLowerCase().includes(event.query.toLowerCase())
3741
})
3842
}
3943
else {
40-
suggestions.value = props.context?.attrs.complete(event.query)
44+
loading.value = true
45+
try {
46+
suggestions.value = await props.context?.attrs.complete(event.query)
47+
}
48+
catch (error) {
49+
console.error('Error fetching suggestions:', error)
50+
suggestions.value = []
51+
}
52+
finally {
53+
loading.value = false
54+
}
4155
}
4256
}
4357
</script>
@@ -60,9 +74,13 @@ function search(event: AutoCompleteCompleteEvent) {
6074
:dropdown="context?.dropdown ?? false"
6175
:multiple="context?.multiple ?? false"
6276
:typeahead="context?.typeahead ?? true"
77+
:min-length="context?.minLength ?? undefined"
78+
:placeholder="context?.placeholder ?? undefined"
79+
:fluid="context?.fluid ?? undefined"
6380
:pt="context?.pt"
6481
:pt-options="context?.ptOptions"
6582
:unstyled="unstyled"
83+
:loading="loading"
6684
@keydown.enter.prevent
6785
@complete="search"
6886
@change="handleInput"

0 commit comments

Comments
 (0)