@@ -18,7 +18,7 @@ import {
18
18
flattenArray ,
19
19
} from './utils'
20
20
21
- const DEFAULT_TRIGGER = 'onChange '
21
+ const DEFAULT_TRIGGER = 'change '
22
22
23
23
function createBaseForm ( option = { } , mixins = [ ] ) {
24
24
const {
@@ -94,7 +94,7 @@ function createBaseForm (option = {}, mixins = []) {
94
94
const valuesAllSet = { }
95
95
valuesAll [ name ] = value
96
96
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 )
98
98
}
99
99
const field = this . fieldsStore . getField ( name )
100
100
return ( { name, field : { ...field , value, touched : true } , fieldMeta } )
@@ -148,7 +148,7 @@ function createBaseForm (option = {}, mixins = []) {
148
148
} ,
149
149
150
150
getFieldDecorator ( name , fieldOption ) {
151
- const { ref , ... restProps } = this . getFieldProps ( name , fieldOption )
151
+ const { directives , props } = this . getFieldProps ( name , fieldOption )
152
152
return ( fieldElem ) => {
153
153
const fieldMeta = this . fieldsStore . getFieldMeta ( name )
154
154
const originalProps = fieldElem . props
@@ -173,10 +173,10 @@ function createBaseForm (option = {}, mixins = []) {
173
173
fieldMeta . ref = fieldElem . ref
174
174
return cloneElement ( fieldElem , {
175
175
props : {
176
- ...restProps ,
176
+ ...props ,
177
177
...this . fieldsStore . getFieldValuePropValue ( fieldMeta ) ,
178
178
} ,
179
- ref ,
179
+ directives ,
180
180
} )
181
181
}
182
182
} ,
@@ -220,25 +220,10 @@ function createBaseForm (option = {}, mixins = []) {
220
220
221
221
const inputProps = {
222
222
...this . fieldsStore . getFieldValuePropValue ( fieldOption ) ,
223
- ref : name ,
223
+ // ref: name,
224
+ on : { } ,
224
225
}
225
226
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
- } )
242
227
if ( fieldNameProp ) {
243
228
inputProps [ fieldNameProp ] = name
244
229
}
@@ -252,7 +237,7 @@ function createBaseForm (option = {}, mixins = []) {
252
237
253
238
// make sure that the value will be collect
254
239
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 )
256
241
}
257
242
258
243
const meta = {
@@ -269,7 +254,14 @@ function createBaseForm (option = {}, mixins = []) {
269
254
inputProps [ fieldDataProp ] = this . fieldsStore . getField ( name )
270
255
}
271
256
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
+ }
273
265
} ,
274
266
275
267
getFieldInstance ( name ) {
@@ -289,9 +281,12 @@ function createBaseForm (option = {}, mixins = []) {
289
281
if ( onFieldsChange ) {
290
282
const changedFields = Object . keys ( fields )
291
283
. 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 ( ) )
293
285
}
294
- this . forceUpdate ( callback )
286
+ this . $forceUpdate ( )
287
+ this . $nextTick ( ( ) => {
288
+ callback && callback ( )
289
+ } )
295
290
} ,
296
291
297
292
resetFields ( ns ) {
@@ -330,11 +325,22 @@ function createBaseForm (option = {}, mixins = []) {
330
325
this . setFields ( newFields , callback )
331
326
if ( onValuesChange ) {
332
327
const allValues = this . fieldsStore . getAllValues ( )
333
- onValuesChange ( this . props , changedValues , allValues )
328
+ onValuesChange ( this . $ props, changedValues , allValues )
334
329
}
335
330
} ,
336
331
337
332
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
+ }
338
344
this . recoverClearedField ( name )
339
345
const fieldMeta = this . fieldsStore . getFieldMeta ( name )
340
346
if ( fieldMeta ) {
0 commit comments