* chore: initial poc * chore: cleanup, log on the docs * feat: add file component * feat: typing for nested config * feat: more props for form field * feat: export field component, expose more slotprops * feat: array, config label * feat: improve array * feat: support custom form state * chore: prevent schema props showing on attribute * feat: dependencies rendering * refactor: change name to fieldName to allow easier slotProps binding * feat: improve file upload * feat: expose custom auto form slot * chore: bump * chore: replicate to default styling * chore: build registry * fix: export component before init * chore: add examples * chore: add form api example * fix: warning in console * chore: bump package version * chore: update example, complete md * feat: allow zod description as label, allow custom component * docs: fix link * feat: show required field for object * chore: replace enumProps
39 lines
938 B
Vue
39 lines
938 B
Vue
<script setup lang="ts">
|
|
import * as z from 'zod'
|
|
import { h } from 'vue'
|
|
import { Button } from '@/lib/registry/default/ui/button'
|
|
import { toast } from '@/lib/registry/default/ui/toast'
|
|
import { AutoForm } from '@/lib/registry/default/ui/auto-form'
|
|
|
|
const schema = z.object({
|
|
guestListName: z.string(),
|
|
invitedGuests: z
|
|
.array(
|
|
z.object({
|
|
name: z.string(),
|
|
age: z.coerce.number(),
|
|
}),
|
|
)
|
|
.describe('Guests invited to the party'),
|
|
})
|
|
|
|
function onSubmit(values: Record<string, any>) {
|
|
toast({
|
|
title: 'You submitted the following values:',
|
|
description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(values, null, 2))),
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<AutoForm
|
|
class="w-2/3 space-y-6"
|
|
:schema="schema"
|
|
@submit="onSubmit"
|
|
>
|
|
<Button type="submit">
|
|
Submit
|
|
</Button>
|
|
</AutoForm>
|
|
</template>
|