From 4357d9b5529f1fbc41658d4c8e3576de4e493d21 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Tue, 5 Dec 2023 22:41:34 +0800 Subject: [PATCH] feat: support FormMessage to be used under root Form --- ee/tabby-ui/components/ui/form.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ee/tabby-ui/components/ui/form.tsx b/ee/tabby-ui/components/ui/form.tsx index 4603f8b..e173b4d 100644 --- a/ee/tabby-ui/components/ui/form.tsx +++ b/ee/tabby-ui/components/ui/form.tsx @@ -43,18 +43,19 @@ const useFormField = () => { const fieldContext = React.useContext(FormFieldContext) const itemContext = React.useContext(FormItemContext) const { getFieldState, formState } = useFormContext() + const name = fieldContext.name || "root"; - const fieldState = getFieldState(fieldContext.name, formState) + const fieldState = getFieldState(name, formState) - if (!fieldContext) { - throw new Error("useFormField should be used within ") + if (!formState) { + throw new Error("useFormField should be used within
") } const { id } = itemContext return { id, - name: fieldContext.name, + name, formItemId: `${id}-form-item`, formDescriptionId: `${id}-form-item-description`, formMessageId: `${id}-form-item-message`,