@@ -18,7 +18,7 @@ import {
1818 flattenArray ,
1919} from './utils'
2020
21- const DEFAULT_TRIGGER = 'onChange '
21+ const DEFAULT_TRIGGER = 'change '
2222
2323function createBaseForm ( option = { } , mixins = [ ] ) {
2424 const {
@@ -94,7 +94,7 @@ function createBaseForm (option = {}, mixins = []) {
9494 const valuesAllSet = { }
9595 valuesAll [ name ] = value
9696 Object . keys ( valuesAll ) . forEach ( key => set ( valuesAllSet , key , valuesAll [ key ] ) )
97- onValuesChange ( this . props , set ( { } , name , value ) , valuesAllSet )
97+ onValuesChange ( this . $ props, set ( { } , name , value ) , valuesAllSet )
9898 }
9999 const field = this . fieldsStore . getField ( name )
100100 return ( { name, field : { ...field , value, touched : true } , fieldMeta } )
@@ -148,7 +148,7 @@ function createBaseForm (option = {}, mixins = []) {
148148 } ,
149149
150150 getFieldDecorator ( name , fieldOption ) {
151- const { ref , ... restProps } = this . getFieldProps ( name , fieldOption )
151+ const { directives , props } = this . getFieldProps ( name , fieldOption )
152152 return ( fieldElem ) => {
153153 const fieldMeta = this . fieldsStore . getFieldMeta ( name )
154154 const originalProps = fieldElem . props
@@ -173,10 +173,10 @@ function createBaseForm (option = {}, mixins = []) {
173173 fieldMeta . ref = fieldElem . ref
174174 return cloneElement ( fieldElem , {
175175 props : {
176- ...restProps ,
176+ ...props ,
177177 ...this . fieldsStore . getFieldValuePropValue ( fieldMeta ) ,
178178 } ,
179- ref ,
179+ directives ,
180180 } )
181181 }
182182 } ,
@@ -220,25 +220,10 @@ function createBaseForm (option = {}, mixins = []) {
220220
221221 const inputProps = {
222222 ...this . fieldsStore . getFieldValuePropValue ( fieldOption ) ,
223- ref : name ,
223+ // ref: name,
224+ on : { } ,
224225 }
225226 const saveRef = this . getCacheBind ( name , `${ name } __ref` , this . saveRef )
226- this . $nextTick ( ( ) => {
227- if ( this . instances [ name ] !== this . $refs [ name ] ) {
228- this . $refs [ name ] . destroyed = ( ) => {
229- this . $refs [ name ] . destroyed ( )
230- // after destroy, delete data
231- this . clearedFieldMetaCache [ name ] = {
232- field : this . fieldsStore . getField ( name ) ,
233- meta : this . fieldsStore . getFieldMeta ( name ) ,
234- }
235- this . fieldsStore . clearField ( name )
236- delete this . instances [ name ]
237- delete this . cachedBind [ name ]
238- }
239- }
240- saveRef ( name , `${ name } __ref` , this . $refs [ name ] )
241- } )
242227 if ( fieldNameProp ) {
243228 inputProps [ fieldNameProp ] = name
244229 }
@@ -252,7 +237,7 @@ function createBaseForm (option = {}, mixins = []) {
252237
253238 // make sure that the value will be collect
254239 if ( trigger && validateTriggers . indexOf ( trigger ) === - 1 ) {
255- inputProps [ trigger ] = this . getCacheBind ( name , trigger , this . onCollect )
240+ inputProps . on [ trigger ] = this . getCacheBind ( name , trigger , this . onCollect )
256241 }
257242
258243 const meta = {
@@ -269,7 +254,14 @@ function createBaseForm (option = {}, mixins = []) {
269254 inputProps [ fieldDataProp ] = this . fieldsStore . getField ( name )
270255 }
271256
272- return inputProps
257+ return {
258+ props : inputProps ,
259+ directives : [
260+ { name : 'ant-form-item-ref-cal' , value : ( component ) => {
261+ saveRef ( component )
262+ } } ,
263+ ] ,
264+ }
273265 } ,
274266
275267 getFieldInstance ( name ) {
@@ -289,9 +281,12 @@ function createBaseForm (option = {}, mixins = []) {
289281 if ( onFieldsChange ) {
290282 const changedFields = Object . keys ( fields )
291283 . reduce ( ( acc , name ) => set ( acc , name , this . fieldsStore . getField ( name ) ) , { } )
292- onFieldsChange ( this . props , changedFields , this . fieldsStore . getNestedAllFields ( ) )
284+ onFieldsChange ( this . $ props, changedFields , this . fieldsStore . getNestedAllFields ( ) )
293285 }
294- this . forceUpdate ( callback )
286+ this . $forceUpdate ( )
287+ this . $nextTick ( ( ) => {
288+ callback && callback ( )
289+ } )
295290 } ,
296291
297292 resetFields ( ns ) {
@@ -330,11 +325,22 @@ function createBaseForm (option = {}, mixins = []) {
330325 this . setFields ( newFields , callback )
331326 if ( onValuesChange ) {
332327 const allValues = this . fieldsStore . getAllValues ( )
333- onValuesChange ( this . props , changedValues , allValues )
328+ onValuesChange ( this . $ props, changedValues , allValues )
334329 }
335330 } ,
336331
337332 saveRef ( name , _ , component ) {
333+ if ( ! component ) {
334+ // after destroy, delete data
335+ this . clearedFieldMetaCache [ name ] = {
336+ field : this . fieldsStore . getField ( name ) ,
337+ meta : this . fieldsStore . getFieldMeta ( name ) ,
338+ }
339+ this . fieldsStore . clearField ( name )
340+ delete this . instances [ name ]
341+ delete this . cachedBind [ name ]
342+ return
343+ }
338344 this . recoverClearedField ( name )
339345 const fieldMeta = this . fieldsStore . getFieldMeta ( name )
340346 if ( fieldMeta ) {
0 commit comments