@@ -2,6 +2,7 @@ import AsyncValidator from 'async-validator';
2
2
import warning from 'warning' ;
3
3
import get from 'lodash/get' ;
4
4
import set from 'lodash/set' ;
5
+ import eq from 'lodash/eq' ;
5
6
import omit from 'lodash/omit' ;
6
7
import createFieldsStore from './createFieldsStore' ;
7
8
import { cloneElement } from '../../_util/vnode' ;
@@ -126,7 +127,14 @@ function createBaseForm(option = {}, mixins = []) {
126
127
const valuesAllSet = { } ;
127
128
valuesAll [ name ] = value ;
128
129
Object . keys ( valuesAll ) . forEach ( key => set ( valuesAllSet , key , valuesAll [ key ] ) ) ;
129
- onValuesChange ( this , set ( { } , name , value ) , valuesAllSet ) ;
130
+ onValuesChange (
131
+ {
132
+ [ formPropName ] : this . getForm ( ) ,
133
+ ...this . $props ,
134
+ } ,
135
+ set ( { } , name , value ) ,
136
+ valuesAllSet ,
137
+ ) ;
130
138
}
131
139
const field = this . fieldsStore . getField ( name ) ;
132
140
return { name, field : { ...field , value, touched : true } , fieldMeta } ;
@@ -135,6 +143,7 @@ function createBaseForm(option = {}, mixins = []) {
135
143
onCollect ( name_ , action , ...args ) {
136
144
const { name, field, fieldMeta } = this . onCollectCommon ( name_ , action , args ) ;
137
145
const { validate } = fieldMeta ;
146
+ this . fieldsStore . setFieldsAsDirty ( ) ;
138
147
const newField = {
139
148
...field ,
140
149
dirty : hasRules ( validate ) ,
@@ -150,6 +159,7 @@ function createBaseForm(option = {}, mixins = []) {
150
159
...field ,
151
160
dirty : true ,
152
161
} ;
162
+ this . fieldsStore . setFieldsAsDirty ( ) ;
153
163
this . validateFieldsInternal ( [ newField ] , {
154
164
action,
155
165
options : {
@@ -243,7 +253,7 @@ function createBaseForm(option = {}, mixins = []) {
243
253
if ( process . env . NODE_ENV !== 'production' ) {
244
254
warning (
245
255
this . fieldsStore . isValidNestedFieldName ( name ) ,
246
- ' One field name cannot be part of another, e.g. `a ` and `a.b`.' ,
256
+ ` One field name cannot be part of another, e.g. \`a\ ` and \ `a.b\`. Check field: ${ name } ` ,
247
257
) ;
248
258
warning (
249
259
! ( 'exclusive' in usersFieldOption ) ,
@@ -346,7 +356,14 @@ function createBaseForm(option = {}, mixins = []) {
346
356
( acc , name ) => set ( acc , name , this . fieldsStore . getField ( name ) ) ,
347
357
{ } ,
348
358
) ;
349
- onFieldsChange ( this , changedFields , this . fieldsStore . getNestedAllFields ( ) ) ;
359
+ onFieldsChange (
360
+ {
361
+ [ formPropName ] : this . getForm ( ) ,
362
+ ...this . $props ,
363
+ } ,
364
+ changedFields ,
365
+ this . fieldsStore . getNestedAllFields ( ) ,
366
+ ) ;
350
367
}
351
368
if ( templateContext ) {
352
369
templateContext . $forceUpdate ( ) ;
@@ -381,7 +398,14 @@ function createBaseForm(option = {}, mixins = []) {
381
398
this . setFields ( newFields , callback ) ;
382
399
if ( onValuesChange ) {
383
400
const allValues = this . fieldsStore . getAllValues ( ) ;
384
- onValuesChange ( this , changedValues , allValues ) ;
401
+ onValuesChange (
402
+ {
403
+ [ formPropName ] : this . getForm ( ) ,
404
+ ...this . $props ,
405
+ } ,
406
+ changedValues ,
407
+ allValues ,
408
+ ) ;
385
409
}
386
410
} ,
387
411
@@ -501,7 +525,38 @@ function createBaseForm(option = {}, mixins = []) {
501
525
} ;
502
526
if ( errors && errors . length ) {
503
527
errors . forEach ( e => {
504
- const fieldName = e . field ;
528
+ const errorFieldName = e . field ;
529
+ let fieldName = errorFieldName ;
530
+
531
+ // Handle using array validation rule.
532
+ // ref: https://github.com/ant-design/ant-design/issues/14275
533
+ Object . keys ( allRules ) . some ( ruleFieldName => {
534
+ const rules = allRules [ ruleFieldName ] || [ ] ;
535
+
536
+ // Exist if match rule
537
+ if ( ruleFieldName === errorFieldName ) {
538
+ fieldName = ruleFieldName ;
539
+ return true ;
540
+ }
541
+
542
+ // Skip if not match array type
543
+ if (
544
+ rules . every ( ( { type } ) => type !== 'array' ) &&
545
+ errorFieldName . indexOf ( ruleFieldName ) !== 0
546
+ ) {
547
+ return false ;
548
+ }
549
+
550
+ // Exist if match the field name
551
+ const restPath = errorFieldName . slice ( ruleFieldName . length + 1 ) ;
552
+ if ( / ^ \d + $ / . test ( restPath ) ) {
553
+ fieldName = ruleFieldName ;
554
+ return true ;
555
+ }
556
+
557
+ return false ;
558
+ } ) ;
559
+
505
560
const field = get ( errorsGroup , fieldName ) ;
506
561
if ( typeof field !== 'object' || Array . isArray ( field ) ) {
507
562
set ( errorsGroup , fieldName , { errors : [ ] } ) ;
@@ -516,7 +571,7 @@ function createBaseForm(option = {}, mixins = []) {
516
571
const fieldErrors = get ( errorsGroup , name ) ;
517
572
const nowField = this . fieldsStore . getField ( name ) ;
518
573
// avoid concurrency problems
519
- if ( nowField . value !== allValues [ name ] ) {
574
+ if ( ! eq ( nowField . value , allValues [ name ] ) ) {
520
575
expired . push ( {
521
576
name,
522
577
} ) ;
@@ -583,9 +638,7 @@ function createBaseForm(option = {}, mixins = []) {
583
638
return field ;
584
639
} ) ;
585
640
if ( ! fields . length ) {
586
- if ( callback ) {
587
- callback ( null , this . fieldsStore . getFieldsValue ( fieldNames ) ) ;
588
- }
641
+ callback ( null , this . fieldsStore . getFieldsValue ( fieldNames ) ) ;
589
642
return ;
590
643
}
591
644
if ( ! ( 'firstFields' in options ) ) {
@@ -604,7 +657,7 @@ function createBaseForm(option = {}, mixins = []) {
604
657
) ;
605
658
} ) ;
606
659
pending . catch ( e => {
607
- if ( console . error ) {
660
+ if ( console . error && process . env . NODE_ENV !== 'production' ) {
608
661
console . error ( e ) ;
609
662
}
610
663
return e ;
@@ -627,7 +680,7 @@ function createBaseForm(option = {}, mixins = []) {
627
680
if ( process . env . NODE_ENV !== 'production' && process . env . NODE_ENV !== 'test' ) {
628
681
warning (
629
682
false ,
630
- '`submit` is deprecated.' +
683
+ '`submit` is deprecated. ' +
631
684
"Actually, it's more convenient to handle submitting status by yourself." ,
632
685
) ;
633
686
}
0 commit comments