docs(form): specify component ref type (#2296)

This commit is contained in:
Asoka Wotulo
2024-10-03 21:43:27 +07:00
committed by GitHub
parent 5ed5c57d0d
commit 33467ad171

View File

@@ -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,