mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
Co-authored-by: Benjamin Canac <canacb1@gmail.com> Co-authored-by: Romain Hamel <rom.hml@gmail.com>
40 lines
936 B
Vue
40 lines
936 B
Vue
<script setup lang="ts">
|
|
import { object, string, nonempty, refine, type Infer } from 'superstruct'
|
|
import type { FormSubmitEvent } from '#ui/types'
|
|
|
|
const schema = object({
|
|
email: nonempty(string()),
|
|
password: refine(string(), 'Password', (value) => {
|
|
if (value.length >= 8) return true
|
|
return 'Must be at least 8 characters'
|
|
})
|
|
})
|
|
|
|
const state = reactive({
|
|
email: '',
|
|
password: ''
|
|
})
|
|
|
|
type Schema = Infer<typeof schema>
|
|
|
|
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|
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>
|