From 8141f53af56fcadc97631db9c16db8ee0b0a56ba Mon Sep 17 00:00:00 2001 From: lyzno1 Date: Thu, 18 Sep 2025 12:48:26 +0800 Subject: [PATCH] fix: add preventDefaultSubmit prop to BaseForm to prevent unwanted page refresh on Enter key --- .../base/form/components/base/base-form.tsx | 13 +++++++++++++ .../subscription-list/create/common-modal.tsx | 1 + 2 files changed, 14 insertions(+) diff --git a/web/app/components/base/form/components/base/base-form.tsx b/web/app/components/base/form/components/base/base-form.tsx index c056829db4..2ecf0dc609 100644 --- a/web/app/components/base/form/components/base/base-form.tsx +++ b/web/app/components/base/form/components/base/base-form.tsx @@ -32,6 +32,8 @@ export type BaseFormProps = { ref?: FormRef disabled?: boolean formFromProps?: AnyFormApi + onSubmit?: (e: React.FormEvent) => void + preventDefaultSubmit?: boolean } & Pick const BaseForm = ({ @@ -45,6 +47,8 @@ const BaseForm = ({ ref, disabled, formFromProps, + onSubmit, + preventDefaultSubmit = false, }: BaseFormProps) => { const initialDefaultValues = useMemo(() => { if (defaultValues) @@ -114,9 +118,18 @@ const BaseForm = ({ if (!formSchemas?.length) return null + const handleSubmit = (e: React.FormEvent) => { + if (preventDefaultSubmit) { + e.preventDefault() + e.stopPropagation() + } + onSubmit?.(e) + } + return (
{formSchemas.map(renderFieldWrapper)}
diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx index a086bb21cf..cea576bb94 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx @@ -218,6 +218,7 @@ export const CommonCreateModal = ({ onClose, createType }: Props) => { formSchemas={credentialsSchema} ref={credentialsFormRef} labelClassName='system-sm-medium mb-2 block text-text-primary' + preventDefaultSubmit={true} /> )}