docs(form): use useTemplateRef

This commit is contained in:
Benjamin Canac
2024-10-15 15:09:21 +02:00
parent 16b48efa96
commit 8258cd3829
5 changed files with 20 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import { z } from 'zod'
import type { FormSubmitEvent, Form } from '@nuxt/ui'
import type { FormSubmitEvent } from '@nuxt/ui'
const schema = z.object({
input: z.string().min(10),
@@ -35,7 +35,8 @@ const schema = z.object({
type Schema = z.output<typeof schema>
const state = reactive<Partial<Schema>>({})
const form = ref<Form<Schema>>()
const form = useTemplateRef('form')
const items = [
{ label: 'Option 1', value: 'option-1' },

View File

@@ -30,7 +30,6 @@ function removeItem() {
state.items.pop()
}
}
const formItemRef = ref()
function onSubmit(event: FormSubmitEvent<Schema>) {
console.log('Success', event.data)
@@ -43,7 +42,6 @@ function onError(event: any) {
<template>
<UForm
ref="formItemRef"
:state="state"
:schema="schema"
class="gap-4 flex flex-col w-60"