mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
docs(form): specify component ref type (#2296)
This commit is contained in:
@@ -117,23 +117,28 @@ You can manually set errors after form submission if required. To do this, simpl
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import type { FormError, FormSubmitEvent } from '#ui/types'
|
||||
import type { Form, FormSubmitEvent } from '#ui/types'
|
||||
|
||||
const state = reactive({
|
||||
interface Schema {
|
||||
email?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
const state = reactive<Schema>({
|
||||
email: undefined,
|
||||
password: undefined
|
||||
})
|
||||
|
||||
const form = ref()
|
||||
const form = ref<Form<Schema>>()
|
||||
|
||||
async function onSubmit (event: FormSubmitEvent<any>) {
|
||||
form.value.clear()
|
||||
async function onSubmit (event: FormSubmitEvent<Schema>) {
|
||||
form.value!.clear()
|
||||
try {
|
||||
const response = await $fetch('...')
|
||||
// ...
|
||||
} catch (err) {
|
||||
if (err.statusCode === 422) {
|
||||
form.value.setErrors(err.data.errors.map((err) => ({
|
||||
form.value!.setErrors(err.data.errors.map((err) => ({
|
||||
// Map validation errors to { path: string, message: string }
|
||||
message: err.message,
|
||||
path: err.path,
|
||||
|
||||
Reference in New Issue
Block a user