mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
46 lines
956 B
Vue
46 lines
956 B
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import { z } from 'zod'
|
|
import type { Form } from '@nuxthq/ui/dist/runtime/types'
|
|
|
|
const schema = z.object({
|
|
emailZod: z.string().email('Invalid email'),
|
|
passwordZod: z.string().min(8, 'Must be at least 8 characters')
|
|
})
|
|
|
|
type Schema = z.output<typeof schema>
|
|
|
|
const state = ref({
|
|
emailZod: undefined,
|
|
passwordZod: undefined
|
|
})
|
|
|
|
const form = ref<Form<Schema>>()
|
|
|
|
async function submit () {
|
|
await form.value!.validate()
|
|
// Do something with state.value
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<UForm
|
|
ref="form"
|
|
:schema="schema"
|
|
:state="state"
|
|
@submit.prevent="submit"
|
|
>
|
|
<UFormGroup label="Email" name="emailZod">
|
|
<UInput v-model="state.emailZod" />
|
|
</UFormGroup>
|
|
|
|
<UFormGroup label="Password" name="passwordZod">
|
|
<UInput v-model="state.passwordZod" type="password" />
|
|
</UFormGroup>
|
|
|
|
<UButton type="submit">
|
|
Submit
|
|
</UButton>
|
|
</UForm>
|
|
</template>
|