@@ -40,7 +40,7 @@ import {
4040} from './utils/valueUtil' ;
4141import type { BatchTask } from './BatchUpdate' ;
4242
43- type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
43+ type FlexibleFieldEntity = Partial < FieldEntity > ;
4444
4545interface UpdateAction {
4646 type : 'updateValue' ;
@@ -282,9 +282,7 @@ export class FormStore {
282282 return cache ;
283283 } ;
284284
285- private getFieldEntitiesForNamePathList = (
286- nameList ?: NamePath [ ] ,
287- ) : ( FieldEntity | InvalidateFieldEntity ) [ ] => {
285+ private getFieldEntitiesForNamePathList = ( nameList ?: NamePath [ ] ) : FlexibleFieldEntity [ ] => {
288286 if ( ! nameList ) {
289287 return this . getFieldEntities ( true ) ;
290288 }
@@ -304,13 +302,11 @@ export class FormStore {
304302 // Fill args
305303 let mergedNameList : NamePath [ ] | true ;
306304 let mergedFilterFunc : FilterFunc ;
307- let mergedStrict : boolean ;
308305
309306 if ( nameList === true || Array . isArray ( nameList ) ) {
310307 mergedNameList = nameList ;
311308 mergedFilterFunc = filterFunc ;
312309 } else if ( nameList && typeof nameList === 'object' ) {
313- mergedStrict = nameList . strict ;
314310 mergedFilterFunc = nameList . filter ;
315311 }
316312
@@ -323,17 +319,15 @@ export class FormStore {
323319 ) ;
324320
325321 const filteredNameList : NamePath [ ] = [ ] ;
326- fieldEntities . forEach ( ( entity : FieldEntity | InvalidateFieldEntity ) => {
327- const namePath =
328- 'INVALIDATE_NAME_PATH' in entity ? entity . INVALIDATE_NAME_PATH : entity . getNamePath ( ) ;
322+ const listNamePaths : InternalNamePath [ ] = [ ] ;
323+
324+ fieldEntities . forEach ( ( entity : FlexibleFieldEntity ) => {
325+ const namePath = entity . INVALIDATE_NAME_PATH || entity . getNamePath ( ) ;
329326
330327 // Ignore when it's a list item and not specific the namePath,
331328 // since parent field is already take in count
332- if ( mergedStrict ) {
333- if ( ( entity as FieldEntity ) . isList ?.( ) ) {
334- return ;
335- }
336- } else if ( ! mergedNameList && ( entity as FieldEntity ) . isListField ?.( ) ) {
329+ if ( ( entity as FieldEntity ) . isList ?.( ) ) {
330+ listNamePaths . push ( namePath ) ;
337331 return ;
338332 }
339333
@@ -347,7 +341,16 @@ export class FormStore {
347341 }
348342 } ) ;
349343
350- return cloneByNamePathList ( this . store , filteredNameList . map ( getNamePath ) ) ;
344+ let mergedValues = cloneByNamePathList ( this . store , filteredNameList . map ( getNamePath ) ) ;
345+
346+ // We need fill the list as [] if Form.List is empty
347+ listNamePaths . forEach ( namePath => {
348+ if ( ! getValue ( mergedValues , namePath ) ) {
349+ mergedValues = setValue ( mergedValues , namePath , [ ] ) ;
350+ }
351+ } ) ;
352+
353+ return mergedValues ;
351354 } ;
352355
353356 private getFieldValue = ( name : NamePath ) => {
@@ -363,7 +366,7 @@ export class FormStore {
363366 const fieldEntities = this . getFieldEntitiesForNamePathList ( nameList ) ;
364367
365368 return fieldEntities . map ( ( entity , index ) => {
366- if ( entity && ! ( 'INVALIDATE_NAME_PATH' in entity ) ) {
369+ if ( entity && ! entity . INVALIDATE_NAME_PATH ) {
367370 return {
368371 name : entity . getNamePath ( ) ,
369372 errors : entity . getErrors ( ) ,
@@ -781,7 +784,10 @@ export class FormStore {
781784
782785 if ( onValuesChange ) {
783786 const changedValues = cloneByNamePathList ( this . store , [ namePath ] ) ;
784- onValuesChange ( changedValues , this . getFieldsValue ( ) ) ;
787+ const allValues = this . getFieldsValue ( ) ;
788+ // Merge changedValues into allValues to ensure allValues contains the latest changes
789+ const mergedAllValues = merge ( allValues , changedValues ) ;
790+ onValuesChange ( changedValues , mergedAllValues ) ;
785791 }
786792
787793 this . triggerOnFieldsChange ( [ namePath , ...childrenFields ] ) ;
@@ -910,6 +916,8 @@ export class FormStore {
910916 const namePathList : InternalNamePath [ ] | undefined = provideNameList
911917 ? nameList . map ( getNamePath )
912918 : [ ] ;
919+ // Same namePathList, but does not include Form.List name
920+ const finalValueNamePathList = [ ...namePathList ] ;
913921
914922 // Collect result in promise list
915923 const promiseList : Promise < FieldError > [ ] = [ ] ;
@@ -921,9 +929,19 @@ export class FormStore {
921929 const { recursive, dirty } = options || { } ;
922930
923931 this . getFieldEntities ( true ) . forEach ( ( field : FieldEntity ) => {
932+ const fieldNamePath = field . getNamePath ( ) ;
933+
924934 // Add field if not provide `nameList`
925935 if ( ! provideNameList ) {
926- namePathList . push ( field . getNamePath ( ) ) ;
936+ if (
937+ // If is field, pass directly
938+ ! field . isList ( ) ||
939+ // If is list, do not add if already exist sub field in the namePathList
940+ ! namePathList . some ( name => matchNamePath ( name , fieldNamePath , true ) )
941+ ) {
942+ finalValueNamePathList . push ( fieldNamePath ) ;
943+ }
944+ namePathList . push ( fieldNamePath ) ;
927945 }
928946
929947 // Skip if without rule
@@ -936,7 +954,6 @@ export class FormStore {
936954 return ;
937955 }
938956
939- const fieldNamePath = field . getNamePath ( ) ;
940957 validateNamePathList . add ( fieldNamePath . join ( TMP_SPLIT ) ) ;
941958
942959 // Add field validate rule in to promise list
@@ -1000,7 +1017,7 @@ export class FormStore {
10001017 const returnPromise : Promise < Store | ValidateErrorEntity | string [ ] > = summaryPromise
10011018 . then ( ( ) : Promise < Store | string [ ] > => {
10021019 if ( this . lastValidatePromise === summaryPromise ) {
1003- return Promise . resolve ( this . getFieldsValue ( namePathList ) ) ;
1020+ return Promise . resolve ( this . getFieldsValue ( finalValueNamePathList ) ) ;
10041021 }
10051022 return Promise . reject < string [ ] > ( [ ] ) ;
10061023 } )
0 commit comments