@@ -239,6 +239,11 @@ export class FormStore {
239239 return this . fieldEntities . filter ( field => field . getNamePath ( ) . length ) ;
240240 } ;
241241
242+ /**
243+ * Get a map of registered field entities with their name path as the key.
244+ * @param pure Only include fields which have a `name`. Default: false
245+ * @returns A NameMap containing field entities indexed by their name paths
246+ */
242247 private getFieldsMap = ( pure : boolean = false ) => {
243248 const cache : NameMap < FieldEntity > = new NameMap ( ) ;
244249 this . getFieldEntities ( pure ) . forEach ( field => {
@@ -248,14 +253,35 @@ export class FormStore {
248253 return cache ;
249254 } ;
250255
251- private getFieldEntitiesForNamePathList = ( nameList ?: NamePath [ ] ) : FlexibleFieldEntity [ ] => {
256+ /**
257+ * Get field entities based on a list of name paths.
258+ * @param nameList - Array of name paths to search for. If not provided, returns all field entities with names.
259+ * @param includesSubNamePath - Whether to include fields that have the given name path as a prefix.
260+ */
261+ private getFieldEntitiesForNamePathList = (
262+ nameList ?: NamePath [ ] ,
263+ includesSubNamePath = false ,
264+ ) : FlexibleFieldEntity [ ] => {
252265 if ( ! nameList ) {
253266 return this . getFieldEntities ( true ) ;
254267 }
255268 const cache = this . getFieldsMap ( true ) ;
256- return nameList . map ( name => {
269+
270+ if ( ! includesSubNamePath ) {
271+ return nameList . map ( name => {
272+ const namePath = getNamePath ( name ) ;
273+ return cache . get ( namePath ) || { INVALIDATE_NAME_PATH : getNamePath ( name ) } ;
274+ } ) ;
275+ }
276+
277+ return nameList . flatMap ( name => {
257278 const namePath = getNamePath ( name ) ;
258- return cache . get ( namePath ) || { INVALIDATE_NAME_PATH : getNamePath ( name ) } ;
279+ const fields : FlexibleFieldEntity [ ] = cache . getAsPrefix ( namePath ) ;
280+
281+ if ( fields . length ) {
282+ return fields ;
283+ }
284+ return [ { INVALIDATE_NAME_PATH : namePath } ] ;
259285 } ) ;
260286 } ;
261287
@@ -282,6 +308,7 @@ export class FormStore {
282308
283309 const fieldEntities = this . getFieldEntitiesForNamePathList (
284310 Array . isArray ( mergedNameList ) ? mergedNameList : null ,
311+ true ,
285312 ) ;
286313
287314 const filteredNameList : NamePath [ ] = [ ] ;
0 commit comments