mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
38 lines
1011 B
Vue
38 lines
1011 B
Vue
<script setup lang="ts">
|
|
import type { FormError, FormSubmitEvent } from '@nuxt/ui'
|
|
|
|
const state = reactive({
|
|
email: undefined,
|
|
password: undefined
|
|
})
|
|
|
|
const validate = (state: any): FormError[] => {
|
|
const errors = []
|
|
if (!state.email) errors.push({ name: 'email', message: 'Required' })
|
|
if (!state.password) errors.push({ name: 'password', message: 'Required' })
|
|
return errors
|
|
}
|
|
|
|
const toast = useToast()
|
|
async function onSubmit(event: FormSubmitEvent<any>) {
|
|
toast.add({ title: 'Success', description: 'The form has been submitted.', color: 'success' })
|
|
console.log(event.data)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<UForm :validate="validate" :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>
|