@@ -57,6 +57,8 @@ export const FormProps = {
57
57
// onSubmit: React.FormEventHandler<any>;
58
58
prefixCls : PropTypes . string ,
59
59
hideRequiredMark : PropTypes . bool ,
60
+ autoFormCreate : PropTypes . func ,
61
+ options : PropTypes . object ,
60
62
}
61
63
62
64
export const ValidationRule = {
@@ -143,23 +145,6 @@ export default {
143
145
fieldDataProp : FIELD_DATA_PROP ,
144
146
} )
145
147
} ,
146
-
147
- // constructor (props) {
148
- // super(props)
149
-
150
- // warning(!props.form, 'It is unnecessary to pass `form` to `Form` after [email protected] .')
151
- // }
152
-
153
- // shouldComponentUpdate(...args) {
154
- // return PureRenderMixin.shouldComponentUpdate.apply(this, args);
155
- // }
156
-
157
- // getChildContext () {
158
- // const { layout } = this.props
159
- // return {
160
- // vertical: layout === 'vertical',
161
- // }
162
- // },
163
148
provide ( ) {
164
149
return {
165
150
FormProps : this . $props ,
@@ -178,7 +163,7 @@ export default {
178
163
179
164
render ( ) {
180
165
const {
181
- prefixCls, hideRequiredMark, layout, onSubmit, $slots,
166
+ prefixCls, hideRequiredMark, layout, onSubmit, $slots, autoFormCreate , options = { } ,
182
167
} = this
183
168
184
169
const formClassName = classNames ( prefixCls , {
@@ -187,6 +172,43 @@ export default {
187
172
[ `${ prefixCls } -inline` ] : layout === 'inline' ,
188
173
[ `${ prefixCls } -hide-required-mark` ] : hideRequiredMark ,
189
174
} )
175
+ if ( autoFormCreate ) {
176
+ const DomForm = this . DomForm || createDOMForm ( {
177
+ fieldNameProp : 'id' ,
178
+ ...options ,
179
+ fieldMetaProp : FIELD_META_PROP ,
180
+ fieldDataProp : FIELD_DATA_PROP ,
181
+ templateContext : this . $parent ,
182
+ } ) ( {
183
+ provide ( ) {
184
+ return {
185
+ decoratorFormProps : this . $props ,
186
+ }
187
+ } ,
188
+ data ( ) {
189
+ return {
190
+ children : $slots . default ,
191
+ formClassName : formClassName ,
192
+ submit : onSubmit ,
193
+ }
194
+ } ,
195
+ created ( ) {
196
+ autoFormCreate ( this . form )
197
+ } ,
198
+ render ( ) {
199
+ const { children, formClassName, submit } = this
200
+ return < form onSubmit = { submit } class = { formClassName } > { children } </ form >
201
+ } ,
202
+ } )
203
+ if ( this . domForm ) {
204
+ this . domForm . children = $slots . default
205
+ this . domForm . submit = onSubmit
206
+ this . domForm . formClassName = formClassName
207
+ }
208
+ this . DomForm = DomForm
209
+
210
+ return < DomForm wrappedComponentRef = { ( inst ) => { this . domForm = inst } } />
211
+ }
190
212
191
213
return < form onSubmit = { onSubmit } class = { formClassName } > { $slots . default } </ form >
192
214
} ,
0 commit comments