@@ -57,6 +57,8 @@ export const FormProps = {
5757 // onSubmit: React.FormEventHandler<any>;
5858 prefixCls : PropTypes . string ,
5959 hideRequiredMark : PropTypes . bool ,
60+ autoFormCreate : PropTypes . func ,
61+ options : PropTypes . object ,
6062}
6163
6264export const ValidationRule = {
@@ -143,23 +145,6 @@ export default {
143145 fieldDataProp : FIELD_DATA_PROP ,
144146 } )
145147 } ,
146-
147- // constructor (props) {
148- // super(props)
149-
150- // warning(!props.form, 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.')
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- // },
163148 provide ( ) {
164149 return {
165150 FormProps : this . $props ,
@@ -178,7 +163,7 @@ export default {
178163
179164 render ( ) {
180165 const {
181- prefixCls, hideRequiredMark, layout, onSubmit, $slots,
166+ prefixCls, hideRequiredMark, layout, onSubmit, $slots, autoFormCreate , options = { } ,
182167 } = this
183168
184169 const formClassName = classNames ( prefixCls , {
@@ -187,6 +172,43 @@ export default {
187172 [ `${ prefixCls } -inline` ] : layout === 'inline' ,
188173 [ `${ prefixCls } -hide-required-mark` ] : hideRequiredMark ,
189174 } )
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+ }
190212
191213 return < form onSubmit = { onSubmit } class = { formClassName } > { $slots . default } </ form >
192214 } ,
0 commit comments