From 09a597f7603fcd28c494efe0408c5fdd36804f64 Mon Sep 17 00:00:00 2001 From: janrywang Date: Sun, 13 Feb 2022 22:07:11 +0800 Subject: [PATCH] feat(antd/next): support 16427form scope with Form --- packages/antd/src/form/index.tsx | 37 +++++++++++++++++++------------- packages/next/src/form/index.tsx | 37 +++++++++++++++++++------------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/packages/antd/src/form/index.tsx b/packages/antd/src/form/index.tsx index 0b4fcb11a12..1c9d688a1ee 100644 --- a/packages/antd/src/form/index.tsx +++ b/packages/antd/src/form/index.tsx @@ -1,6 +1,11 @@ import React from 'react' import { Form as FormType, IFormFeedback } from '@formily/core' -import { useForm, FormProvider, JSXComponent } from '@formily/react' +import { + useForm, + FormProvider, + ExpressionScope, + JSXComponent, +} from '@formily/react' import { FormLayout, IFormLayoutProps } from '../form-layout' import { PreviewText } from '../preview-text' export interface FormProps extends IFormLayoutProps { @@ -21,21 +26,23 @@ export const Form: React.FC = ({ }) => { const top = useForm() const renderContent = (form: FormType) => ( - - - {React.createElement( - component, - { - onSubmit(e: React.FormEvent) { - e?.stopPropagation?.() - e?.preventDefault?.() - form.submit(onAutoSubmit).catch(onAutoSubmitFailed) + + + + {React.createElement( + component, + { + onSubmit(e: React.FormEvent) { + e?.stopPropagation?.() + e?.preventDefault?.() + form.submit(onAutoSubmit).catch(onAutoSubmitFailed) + }, }, - }, - props.children - )} - - + props.children + )} + + + ) if (form) return {renderContent(form)} diff --git a/packages/next/src/form/index.tsx b/packages/next/src/form/index.tsx index d50306f1195..cf2ee710e7c 100644 --- a/packages/next/src/form/index.tsx +++ b/packages/next/src/form/index.tsx @@ -1,5 +1,10 @@ import React, { useMemo } from 'react' -import { FormProvider, JSXComponent, useForm } from '@formily/react' +import { + FormProvider, + ExpressionScope, + JSXComponent, + useForm, +} from '@formily/react' import { FormLayout, IFormLayoutProps } from '../form-layout' import { ConfigProvider } from '@alifd/next' import { @@ -34,21 +39,23 @@ export const Form: React.FC = ({ }, [lang]) const renderContent = (form: FormType) => ( - - - {React.createElement( - component, - { - onSubmit(e: React.FormEvent) { - e?.stopPropagation?.() - e?.preventDefault?.() - form.submit(onAutoSubmit).catch(onAutoSubmitFailed) + + + + {React.createElement( + component, + { + onSubmit(e: React.FormEvent) { + e?.stopPropagation?.() + e?.preventDefault?.() + form.submit(onAutoSubmit).catch(onAutoSubmitFailed) + }, }, - }, - props.children - )} - - + props.children + )} + + + ) if (form)