From 1c562463b23cb7090f98ccb2b605b40dd29a4eec Mon Sep 17 00:00:00 2001 From: zernonia Date: Fri, 19 Apr 2024 13:21:52 +0800 Subject: [PATCH] feat: improve array --- .../registry/new-york/example/AutoForm.vue | 13 ++-- .../new-york/ui/auto-form/AutoForm.vue | 16 +++-- .../new-york/ui/auto-form/fields/Array.vue | 63 +++++++++++-------- .../new-york/ui/auto-form/fields/Object.vue | 2 +- .../lib/registry/new-york/ui/form/index.ts | 2 +- .../registry/new-york/ui/form/useFormField.ts | 1 - 6 files changed, 55 insertions(+), 42 deletions(-) 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 5651ebfb..8928b368 100644 --- a/apps/www/src/lib/registry/new-york/example/AutoForm.vue +++ b/apps/www/src/lib/registry/new-york/example/AutoForm.vue @@ -18,23 +18,18 @@ const schema = z.object({ }), ).default([ { name: '123', age: 30 }, + { name: '456', age: 30 }, ]).describe('How many guests'), - list: z.array(z.string()).describe('test the config'), + list: z.array(z.string()).describe('test the config').min(1, 'Please add some item').default([]), }) -const formSchema = toTypedSchema(schema) - -const { handleSubmit } = useForm({ - validationSchema: formSchema, -}) - -const onSubmit = handleSubmit((values) => { +function onSubmit(values: Record) { 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))), }) -}) +}