mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Benjamin Canac <canacb1@gmail.com>
42 lines
1.0 KiB
Vue
42 lines
1.0 KiB
Vue
<script setup lang="ts">
|
|
import { object, string } from 'yup'
|
|
import type { InferType } from 'yup'
|
|
import type { FormSubmitEvent } from '@nuxt/ui'
|
|
|
|
const schema = object({
|
|
email: string().email('Invalid email').required('Required'),
|
|
password: string()
|
|
.min(8, 'Must be at least 8 characters')
|
|
.required('Required')
|
|
})
|
|
|
|
type Schema = InferType<typeof schema>
|
|
|
|
const state = reactive({
|
|
email: undefined,
|
|
password: undefined
|
|
})
|
|
|
|
const toast = useToast()
|
|
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|
toast.add({ title: 'Success', description: 'The form has been submitted.', color: 'success' })
|
|
console.log(event.data)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
|
|
<UFormField label="Email" name="email">
|
|
<UInput v-model="state.email" />
|
|
</UFormField>
|
|
|
|
<UFormField label="Password" name="password">
|
|
<UInput v-model="state.password" type="password" />
|
|
</UFormField>
|
|
|
|
<UButton type="submit">
|
|
Submit
|
|
</UButton>
|
|
</UForm>
|
|
</template>
|