mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
38 lines
899 B
Vue
38 lines
899 B
Vue
<script setup lang="ts">
|
|
import * as v from 'valibot'
|
|
import type { FormSubmitEvent } from '#ui/types'
|
|
|
|
const schema = v.object({
|
|
email: v.pipe(v.string(), v.email('Invalid email')),
|
|
password: v.pipe(v.string(), v.minLength(8, 'Must be at least 8 characters'))
|
|
})
|
|
|
|
type Schema = v.InferOutput<typeof schema>
|
|
|
|
const state = reactive({
|
|
email: '',
|
|
password: ''
|
|
})
|
|
|
|
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|
// Do something with event.data
|
|
console.log(event.data)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
|
|
<UFormGroup label="Email" name="email">
|
|
<UInput v-model="state.email" />
|
|
</UFormGroup>
|
|
|
|
<UFormGroup label="Password" name="password">
|
|
<UInput v-model="state.password" type="password" />
|
|
</UFormGroup>
|
|
|
|
<UButton type="submit">
|
|
Submit
|
|
</UButton>
|
|
</UForm>
|
|
</template>
|