diff --git a/apps/www/src/lib/registry/new-york/example/AutoForm.vue b/apps/www/src/lib/registry/new-york/example/AutoForm.vue index 6590c18d..8e88a1c9 100644 --- a/apps/www/src/lib/registry/new-york/example/AutoForm.vue +++ b/apps/www/src/lib/registry/new-york/example/AutoForm.vue @@ -3,25 +3,35 @@ import * as z from 'zod' import { h, reactive, ref } from 'vue' import { useForm } from 'vee-validate' import { toTypedSchema } from '@vee-validate/zod' +import { DependencyType } from '../ui/auto-form/interface' import { Button } from '@/lib/registry/new-york/ui/button' import { toast } from '@/lib/registry/new-york/ui/toast' import type { Config } from '@/lib/registry/new-york/ui/auto-form' -import { AutoForm as AutoFormComponent, AutoFormField } from '@/lib/registry/new-york/ui/auto-form' +import { AutoForm, AutoFormField } from '@/lib/registry/new-york/ui/auto-form' const schema = z.object({ - guestListName: z.string(), + age: z.number().default(20), + parentsAllowed: z.boolean().optional(), + vegetarian: z.boolean().default(true), + mealOptions: z.enum(['Pasta', 'Salad', 'Beef Wellington']).optional(), invitedGuests: z .array( z.object({ name: z.string(), age: z.coerce.number(), }), - ).default([ - { name: '123', age: 30 }, - { name: '456', age: 30 }, - ]).describe('How many guests'), + ).default([{ name: '123', age: 0 }]), - list: z.array(z.string()).describe('test the config').min(1, 'Please add some item').default([]), + subObject: z.object({ + subField: z.string().optional().default('Sub Field'), + numberField: z.number().optional().default(10), + + subSubObject: z + .object({ + subSubField: z.string().default('Sub Sub Field'), + }) + .describe('Sub Sub Object Description'), + }), }) function onSubmit(values: Record) { @@ -30,42 +40,64 @@ function onSubmit(values: Record) { 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))), }) } - -const form = useForm({ - keepValuesOnUnmount: true, // make sure the array/object field doesn't destroy the linked field - validationSchema: toTypedSchema(schema), -}) - -form.setValues({ - guestListName: 'testing 123', -}) diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue index d70a4c0b..c8b8cd90 100644 --- a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue @@ -1,30 +1,36 @@