mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(front): enhance InputField component with validation support and error messaging
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user