Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ const Form = forwardRefWithStatics(
form?.getInternalHooks?.(HOOK_MARK)?.flashQueue?.();
}, [form]);

// Dialog / Popup 等通过 Portal 渲染时,DOM 已脱离外层 Form,但 React 合成事件仍沿 Fiber 树冒泡
// 会导致内层 Form 的 reset / submit 误触发外层 Form 的处理逻辑
// 这里过滤掉来自嵌套 Form 的伪冒泡事件
function isEventFromSelf(e: React.FormEvent<HTMLFormElement>) {
return e?.target === formRef.current;
}

function onResetHandler(e: React.FormEvent<HTMLFormElement>) {
if (!isEventFromSelf(e)) return;
[...formMapRef.current.values()].forEach((formItemRef) => {
formItemRef?.current.resetField();
});
Expand All @@ -76,6 +84,11 @@ const Form = forwardRefWithStatics(
onReset?.({ e });
}

function onSubmitHandler(e: React.FormEvent<HTMLFormElement>) {
if (!isEventFromSelf(e)) return;
formInstance.submit(e);
}

function onFormItemValueChange(changedValue: Record<string, unknown>) {
requestAnimationFrame(() => {
const allFields = formInstance.getFieldsValue(true);
Expand Down Expand Up @@ -112,7 +125,7 @@ const Form = forwardRefWithStatics(
id={id}
style={style}
className={formClass}
onSubmit={formInstance.submit}
onSubmit={onSubmitHandler}
onReset={onResetHandler}
>
{children}
Expand Down
Loading