feat(front): enhance InputField component with validation support and error messaging

This commit is contained in:
keven1024
2026-04-26 22:05:47 +08:00
parent c841d8e1a2
commit 6edb1fe222

View File

@@ -1,16 +1,21 @@
<template>
<Field :name="props.name" v-slot="{ field }">
<div class="flex flex-col gap-2">
<Label v-if="props.label">{{ props.label }}</Label>
<Input v-bind="{ ...field, ...$attrs }" />
</div>
</Field>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { Label } from '@/components/ui/label' import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input' import { Input } from '@/components/ui/input'
import type { RuleExpression } from 'vee-validate'
const props = defineProps<{ const props = defineProps<{
name: string name: string
label?: string label?: string
rules?: RuleExpression<string>
}>() }>()
const { value, errorMessage } = useField<string>(props.name, props.rules)
</script> </script>
<template>
<div class="flex flex-col gap-2">
<Label v-if="props.label">{{ props.label }}</Label>
<Input v-model="value" :aria-invalid="!!errorMessage || undefined" v-bind="$attrs" />
<p v-if="errorMessage" class="text-sm text-destructive">{{ errorMessage }}</p>
</div>
</template>