File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ node_modules
4
4
coverage /
5
5
es /
6
6
lib /
7
- ~ *
7
+ ~ *
8
+ yarn.lock
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import Form , { Field , useForm } from '../src/' ;
3
+ import Input from './components/Input' ;
4
+
5
+
6
+ export default ( ) => {
7
+ const [ form ] = useForm ( ) ;
8
+ return (
9
+ < form onSubmit = { event => {
10
+ event . preventDefault ( ) ;
11
+ event . stopPropagation ( ) ;
12
+ form . validateFields ( ) . then ( function ( values ) {
13
+ console . log ( values ) ;
14
+ } ) // Do nothing about submit catch
15
+ . catch ( function ( e ) {
16
+ return e ;
17
+ } ) ;
18
+ } } >
19
+ < Form notContainForm form = { form } >
20
+ < Field name = "username" >
21
+ < Input placeholder = "Username" />
22
+ </ Field >
23
+ < Field name = "password" >
24
+ < Input placeholder = "Password" />
25
+ </ Field >
26
+ </ Form >
27
+ < button type = "submit" > submit</ button >
28
+ </ form >
29
+ ) ;
30
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ export interface FormProps extends BaseFormProps {
22
22
fields ?: FieldData [ ] ;
23
23
name ?: string ;
24
24
validateMessages ?: ValidateMessages ;
25
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ ?: {
26
+ NOT_CONTAIN_FORM ?: boolean ;
27
+ HOOK_MARK : string ;
28
+ } ;
25
29
onValuesChange ?: Callbacks [ 'onValuesChange' ] ;
26
30
onFieldsChange ?: Callbacks [ 'onFieldsChange' ] ;
27
31
onFinish ?: ( values : Store ) => void ;
@@ -38,6 +42,7 @@ const Form: React.FunctionComponent<FormProps> = (
38
42
onValuesChange,
39
43
onFieldsChange,
40
44
onFinish,
45
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ ,
41
46
...restProps
42
47
} : FormProps ,
43
48
ref ,
@@ -105,6 +110,19 @@ const Form: React.FunctionComponent<FormProps> = (
105
110
}
106
111
prevFieldsRef . current = fields ;
107
112
113
+ if (
114
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ &&
115
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ . NOT_CONTAIN_FORM &&
116
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ . HOOK_MARK ===
117
+ 'asdihasiodhaohdioahfoihsoefhisihifhsiofhiosfd'
118
+ ) {
119
+ return (
120
+ < FieldContext . Provider value = { formInstance as InternalFormInstance } >
121
+ { childrenNode }
122
+ </ FieldContext . Provider >
123
+ ) ;
124
+ }
125
+
108
126
return (
109
127
< form
110
128
{ ...restProps }
Original file line number Diff line number Diff line change @@ -25,6 +25,21 @@ describe('Basic', () => {
25
25
expect ( wrapper . find ( 'input' ) . length ) . toBe ( 2 ) ;
26
26
} ) ;
27
27
28
+ it ( 'notContainForm' , ( ) => {
29
+ const wrapper = mount (
30
+ < Form
31
+ __COMPATIBILITY_USAGE_OR_YOU_WILL_BE_FIRED__ = { {
32
+ NOT_CONTAIN_FORM : true ,
33
+ HOOK_MARK : 'asdihasiodhaohdioahfoihsoefhisihifhsiofhiosfd' ,
34
+ } }
35
+ >
36
+ { renderContent ( ) }
37
+ </ Form > ,
38
+ ) ;
39
+ expect ( wrapper . find ( 'form' ) . length ) . toBe ( 0 ) ;
40
+ expect ( wrapper . find ( 'input' ) . length ) . toBe ( 2 ) ;
41
+ } ) ;
42
+
28
43
describe ( 'render props' , ( ) => {
29
44
it ( 'normal' , ( ) => {
30
45
const wrapper = mount ( < Form > { renderContent } </ Form > ) ;
You can’t perform that action at this time.
0 commit comments