Skip to content

Commit

Permalink
docs(form): specify component ref type (nuxt#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
asokawotulo authored and patrick-hofmann committed Oct 3, 2024
1 parent 435bf48 commit f475865
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions docs/content/2.components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f475865

Please sign in to comment.