File tree Expand file tree Collapse file tree 2 files changed +44
-30
lines changed Expand file tree Collapse file tree 2 files changed +44
-30
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { Form as FormType , IFormFeedback } from '@formily/core'
3
- import { useForm , FormProvider , JSXComponent } from '@formily/react'
3
+ import {
4
+ useForm ,
5
+ FormProvider ,
6
+ ExpressionScope ,
7
+ JSXComponent ,
8
+ } from '@formily/react'
4
9
import { FormLayout , IFormLayoutProps } from '../form-layout'
5
10
import { PreviewText } from '../preview-text'
6
11
export interface FormProps extends IFormLayoutProps {
@@ -21,21 +26,23 @@ export const Form: React.FC<FormProps> = ({
21
26
} ) => {
22
27
const top = useForm ( )
23
28
const renderContent = ( form : FormType ) => (
24
- < PreviewText . Placeholder value = { previewTextPlaceholder } >
25
- < FormLayout { ...props } >
26
- { React . createElement (
27
- component ,
28
- {
29
- onSubmit ( e : React . FormEvent ) {
30
- e ?. stopPropagation ?.( )
31
- e ?. preventDefault ?.( )
32
- form . submit ( onAutoSubmit ) . catch ( onAutoSubmitFailed )
29
+ < ExpressionScope value = { { $$form : form } } >
30
+ < PreviewText . Placeholder value = { previewTextPlaceholder } >
31
+ < FormLayout { ...props } >
32
+ { React . createElement (
33
+ component ,
34
+ {
35
+ onSubmit ( e : React . FormEvent ) {
36
+ e ?. stopPropagation ?.( )
37
+ e ?. preventDefault ?.( )
38
+ form . submit ( onAutoSubmit ) . catch ( onAutoSubmitFailed )
39
+ } ,
33
40
} ,
34
- } ,
35
- props . children
36
- ) }
37
- </ FormLayout >
38
- </ PreviewText . Placeholder >
41
+ props . children
42
+ ) }
43
+ </ FormLayout >
44
+ </ PreviewText . Placeholder >
45
+ </ ExpressionScope >
39
46
)
40
47
if ( form )
41
48
return < FormProvider form = { form } > { renderContent ( form ) } </ FormProvider >
Original file line number Diff line number Diff line change 1
1
import React , { useMemo } from 'react'
2
- import { FormProvider , JSXComponent , useForm } from '@formily/react'
2
+ import {
3
+ FormProvider ,
4
+ ExpressionScope ,
5
+ JSXComponent ,
6
+ useForm ,
7
+ } from '@formily/react'
3
8
import { FormLayout , IFormLayoutProps } from '../form-layout'
4
9
import { ConfigProvider } from '@alifd/next'
5
10
import {
@@ -34,21 +39,23 @@ export const Form: React.FC<FormProps> = ({
34
39
} , [ lang ] )
35
40
36
41
const renderContent = ( form : FormType ) => (
37
- < PreviewText . Placeholder value = { previewTextPlaceholder } >
38
- < FormLayout { ...props } >
39
- { React . createElement (
40
- component ,
41
- {
42
- onSubmit ( e : React . FormEvent ) {
43
- e ?. stopPropagation ?.( )
44
- e ?. preventDefault ?.( )
45
- form . submit ( onAutoSubmit ) . catch ( onAutoSubmitFailed )
42
+ < ExpressionScope value = { { $$form : form } } >
43
+ < PreviewText . Placeholder value = { previewTextPlaceholder } >
44
+ < FormLayout { ...props } >
45
+ { React . createElement (
46
+ component ,
47
+ {
48
+ onSubmit ( e : React . FormEvent ) {
49
+ e ?. stopPropagation ?.( )
50
+ e ?. preventDefault ?.( )
51
+ form . submit ( onAutoSubmit ) . catch ( onAutoSubmitFailed )
52
+ } ,
46
53
} ,
47
- } ,
48
- props . children
49
- ) }
50
- </ FormLayout >
51
- </ PreviewText . Placeholder >
54
+ props . children
55
+ ) }
56
+ </ FormLayout >
57
+ </ PreviewText . Placeholder >
58
+ </ ExpressionScope >
52
59
)
53
60
54
61
if ( form )
You can’t perform that action at this time.
0 commit comments