mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-18 14:08:06 +01:00
feat(FormGroup): add eager validation (#992)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<UForm :schema="schema" :state="state" class="space-y-4">
|
||||
<UFormGroup label="Username" name="username" eager-validation>
|
||||
<UInput v-model="state.username" placeholder="Choose Username" />
|
||||
</UFormGroup>
|
||||
</UForm>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { z } from 'zod'
|
||||
|
||||
const schema = z.object({
|
||||
username: z.string().min(10, 'Must be at least 10 characters')
|
||||
})
|
||||
|
||||
const state = reactive({
|
||||
username: undefined
|
||||
})
|
||||
</script>
|
||||
@@ -161,6 +161,10 @@ async function onSubmit (event: FormSubmitEvent<any>) {
|
||||
|
||||
The Form component automatically triggers validation upon `submit`, `input`, `blur` or `change` events. This ensures that any errors are displayed as soon as the user interacts with the form elements. You can control when validation happens this using the `validate-on` prop.
|
||||
|
||||
::callout{icon="i-heroicons-light-bulb"}
|
||||
Note that the `input` event is not triggered until after the initial `blur` event. This is to prevent the form from being validated as the user is typing. You can override this behavior by setting the [`eager-validation`](/forms/form-group#eager-validation) prop on [`FormGroup`](/forms/form-group) to `true`.
|
||||
::
|
||||
|
||||
::component-example
|
||||
---
|
||||
component: 'form-example-elements'
|
||||
|
||||
@@ -163,6 +163,12 @@ code: >-
|
||||
This will only work with form elements that support the `size` prop.
|
||||
::
|
||||
|
||||
### Eager Validation
|
||||
|
||||
By default, validation is only triggered after the initial `blur` event. This is to prevent the form from being validated as the user is typing. You can override this behavior by setting the `eager-validation` prop to `true`
|
||||
|
||||
:component-example{component="form-group-eager-validation-example"}
|
||||
|
||||
## Slots
|
||||
|
||||
### `label`
|
||||
|
||||
Reference in New Issue
Block a user