yunohost-portal/components/TextInput.vue

46 lines
1 KiB
Vue
Raw Permalink Normal View History

2023-07-25 19:19:27 +02:00
<script setup lang="ts">
import { useField } from 'vee-validate'
import { formGroupExtras } from '@/composables/form'
2023-07-26 05:19:52 +02:00
const props = withDefaults(
defineProps<{
name: string
type: HTMLInputElement['type']
}>(),
2023-07-27 17:41:14 +02:00
{},
2023-07-26 05:19:52 +02:00
)
2023-07-25 19:19:27 +02:00
const attrs = useAttrs()
const { describedBy, invalid } = inject(formGroupExtras, {
describedBy: ref(undefined),
invalid: ref(false),
})
const { value, handleBlur, handleChange, errorMessage } = useField(
() => props.name,
{
validateOnValueUpdate: false,
},
)
const validationListeners = {
blur: (e: FocusEvent) => handleBlur(e, true),
change: handleChange,
input: (e: InputEvent) => handleChange(e, !!errorMessage.value),
}
</script>
<template>
2023-11-14 19:17:04 +01:00
<!-- eslint-disable-next-line vuejs-accessibility/form-control-has-label -->
2023-07-25 19:19:27 +02:00
<input
:id="name"
:value="value"
:name="name"
:type="type"
:aria-invalid="invalid"
:aria-describedby="describedBy"
class="input input-bordered"
:class="{ 'input-error': invalid }"
v-bind="attrs"
v-on="validationListeners"
/>
</template>