From a04580a7a6adf0be33e09d4eb1bd392348b0dd7a Mon Sep 17 00:00:00 2001 From: Kiran Kunigiri Date: Sat, 30 Nov 2024 03:37:10 -0800 Subject: [PATCH] Added form templates - Use data-field-name to pass a custom element for a field - Use data-placeholder-name to create a slot placeholder for an element in the form --- example-client/src/routes/rooms/$id.tsx | 33 ++++---- package/src/form/form.tsx | 108 ++++++++++++++++++++++-- 2 files changed, 118 insertions(+), 23 deletions(-) diff --git a/example-client/src/routes/rooms/$id.tsx b/example-client/src/routes/rooms/$id.tsx index 1605b87..c5b5855 100644 --- a/example-client/src/routes/rooms/$id.tsx +++ b/example-client/src/routes/rooms/$id.tsx @@ -1,40 +1,39 @@ -import { Button, Textarea } from '@mantine/core'; +import { Button, Divider, Textarea } from '@mantine/core'; import { createFileRoute } from '@tanstack/react-router'; import { useRef } from 'react'; import { meta } from '~client/form/form-config'; import { DetailHeader } from '~client/form/lib/detail-header'; import MantineZenstackUpdateForm from '~client/form/lib/mantine-update-form'; -import type { ZenstackFormRef } from '~zenstack-ui/index'; +import { type ZenstackFormRef } from '~zenstack-ui/index'; export const Route = createFileRoute('/rooms/$id')({ component: PeopleDetail, }); -// Override metadata to hide the aiSummary field -const metadataOverride = JSON.parse(JSON.stringify(meta)); -metadataOverride.models.room.fields.aiSummary.hidden = true; - function PeopleDetail() { const params = Route.useParams() as { id: string }; const id = Number(params.id); + // Example of useRef to get the form const formRef = useRef(null); - const form = formRef.current?.form; - - const handleSomeAction = () => { - formRef.current?.form.reset(); - }; return (
- -