Files
ui/playground/app/pages/components/form-field.vue
Romain Hamel 5829aebe7d feat(FormField): display multiple errors
Adds the `errors` and `maxErrors` properties to the FormField component which
allows to display multiple errors. The `maxErrors` prop is used to limit
the number of errors displayed and defaults to 1 for backward
compatibility.

This change is compatible with the `Form` component error's too.

Resolves #2389
2025-06-14 17:19:16 +02:00

53 lines
1.4 KiB
Vue

<script setup lang="ts">
import theme from '#build/ui/form-field'
const sizes = Object.keys(theme.variants.size) as Array<keyof typeof theme.variants.size>
const feedbacks = [
{ description: 'This is a description' },
{ error: true },
{ error: 'This is an error' },
{ errors: ['This is an error', 'This is another error', 'This one is not visible'], maxErrors: 2 },
{ hint: 'This is a hint' },
{ help: 'Help! I need somebody!' },
{ required: true }
]
</script>
<template>
<div class="flex flex-col items-center gap-4">
<div class="flex flex-col gap-4 ms-[-92px]">
<div v-for="(feedback, count) in feedbacks" :key="count" class="flex items-center">
<UFormField v-bind="feedback" label="Email" name="email">
<UInput placeholder="john@lennon.com" />
</UFormField>
</div>
</div>
<div class="flex items-center gap-4">
<UFormField
v-for="size in sizes"
:key="size"
:size="size"
label="Email"
name="email"
>
<UInput placeholder="john@lennon.com" />
</UFormField>
</div>
<div class="flex items-center gap-4">
<UFormField
v-for="size in sizes"
:key="size"
:size="size"
label="Email"
description="This is a description"
name="email"
>
<UInput placeholder="john@lennon.com" />
</UFormField>
</div>
</div>
</template>