homemanager-fe/src/components/form/fields/FormAutocompleteField.vue

56 lines
1.3 KiB
Vue
Raw Normal View History

2023-01-27 16:27:14 +00:00
<template>
<FormField
:name="name"
:label="label"
:placeholder="placeholder"
:disabled="disabled"
2023-01-27 18:11:20 +00:00
:required="required"
2023-01-27 16:27:14 +00:00
>
2023-01-27 18:11:20 +00:00
<template #input="{ invalid, id, value, setValue }">
2023-01-27 16:27:14 +00:00
<Autocomplete
2023-01-27 18:11:20 +00:00
:for-id="id"
2023-01-27 16:27:14 +00:00
:invalid="invalid"
:disabled="disabled"
:initialOptions="initialOptions"
:searchFn="searchFn"
:bindValue="bindValue"
:bindLabel="bindLabel"
:placeholder="placeholder"
:model-value="value"
@update:model-value="(newValue) => setValue(newValue)"
>
<template #notfound="slotProps">
<slot name="notfound" v-bind="slotProps" />
</template>
<template #option="slotProps">
<slot name="option" v-bind="slotProps" />
</template>
</Autocomplete>
</template>
<template #default><slot /></template>
</FormField>
</template>
<script setup lang="ts">
import FormField from '../FormField.vue';
import Autocomplete from '../base/Autocomplete.vue';
const props = withDefaults(
defineProps<{
label: string;
name: string;
initialOptions?: any[];
searchFn?: (query: string) => Promise<any[]>;
bindValue?: string;
bindLabel?: string | ((obj: any) => string);
disabled?: boolean;
2023-01-27 18:11:20 +00:00
required?: boolean;
2023-01-27 16:27:14 +00:00
placeholder?: string;
}>(),
{
disabled: false,
}
);
</script>