Skip to content

Commit 2fcd37a

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

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/components/PrimeAutoComplete.vue

Lines changed: 21 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,27 @@ 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+
}
55+
suggestions.value = await props.context?.attrs.complete(event.query)
4156
}
4257
}
4358
</script>
@@ -60,9 +75,13 @@ function search(event: AutoCompleteCompleteEvent) {
6075
:dropdown="context?.dropdown ?? false"
6176
:multiple="context?.multiple ?? false"
6277
:typeahead="context?.typeahead ?? true"
78+
:min-length="context?.minLength ?? undefined"
79+
:placeholder="context?.placeholder ?? undefined"
80+
:fluid="context?.fluid ?? undefined"
6381
:pt="context?.pt"
6482
:pt-options="context?.ptOptions"
6583
:unstyled="unstyled"
84+
:loading="loading"
6685
@keydown.enter.prevent
6786
@complete="search"
6887
@change="handleInput"

0 commit comments

Comments
 (0)