@@ -18,6 +18,7 @@ import {
18
18
ValidateErrorEntity ,
19
19
StoreValue ,
20
20
Meta ,
21
+ InternalFieldData ,
21
22
} from './interface' ;
22
23
import { HOOK_MARK } from './FieldContext' ;
23
24
import { allPromiseFinish } from './utils/asyncUtil' ;
@@ -347,16 +348,22 @@ export class FormStore {
347
348
} ) ;
348
349
} ;
349
350
350
- private getFields = ( ) : FieldData [ ] =>
351
+ private getFields = ( ) : InternalFieldData [ ] =>
351
352
this . getFieldEntities ( true ) . map (
352
- ( field : FieldEntity ) : FieldData => {
353
+ ( field : FieldEntity ) : InternalFieldData => {
353
354
const namePath = field . getNamePath ( ) ;
354
355
const meta = field . getMeta ( ) ;
355
- return {
356
+ const fieldData = {
356
357
...meta ,
357
358
name : namePath ,
358
359
value : this . getFieldValue ( namePath ) ,
359
360
} ;
361
+
362
+ Object . defineProperty ( fieldData , 'originRCField' , {
363
+ value : true ,
364
+ } ) ;
365
+
366
+ return fieldData ;
360
367
} ,
361
368
) ;
362
369
@@ -487,11 +494,30 @@ export class FormStore {
487
494
return childrenFields ;
488
495
} ;
489
496
490
- private triggerOnFieldsChange = ( namePathList : InternalNamePath [ ] ) => {
497
+ private triggerOnFieldsChange = (
498
+ namePathList : InternalNamePath [ ] ,
499
+ filedErrors ?: FieldError [ ] ,
500
+ ) => {
491
501
const { onFieldsChange } = this . callbacks ;
492
502
493
503
if ( onFieldsChange ) {
494
504
const fields = this . getFields ( ) ;
505
+
506
+ /**
507
+ * Fill errors since `fields` may be replaced by controlled fields
508
+ */
509
+ if ( filedErrors ) {
510
+ const cache = new NameMap < string [ ] > ( ) ;
511
+ filedErrors . forEach ( ( { name, errors } ) => {
512
+ cache . set ( name , errors ) ;
513
+ } ) ;
514
+
515
+ fields . forEach ( field => {
516
+ // eslint-disable-next-line no-param-reassign
517
+ field . errors = cache . get ( field . name ) || field . errors ;
518
+ } ) ;
519
+ }
520
+
495
521
const changedFields = fields . filter ( ( { name : fieldName } ) =>
496
522
containsNamePath ( namePathList , fieldName as InternalNamePath ) ,
497
523
) ;
@@ -565,7 +591,7 @@ export class FormStore {
565
591
this . notifyObservers ( this . store , resultNamePathList , {
566
592
type : 'validateFinish' ,
567
593
} ) ;
568
- this . triggerOnFieldsChange ( resultNamePathList ) ;
594
+ this . triggerOnFieldsChange ( resultNamePathList , results ) ;
569
595
} ) ;
570
596
571
597
const returnPromise : Promise < Store | ValidateErrorEntity | string [ ] > = summaryPromise
0 commit comments