@@ -17,6 +17,7 @@ import {
1717 InternalFormInstance ,
1818 ValidateErrorEntity ,
1919 StoreValue ,
20+ Meta ,
2021} from './interface' ;
2122import { HOOK_MARK } from './FieldContext' ;
2223import { allPromiseFinish } from './utils/asyncUtil' ;
@@ -161,14 +162,42 @@ export class FormStore {
161162 return cache ;
162163 } ;
163164
164- private getFieldsValue = ( nameList ?: NamePath [ ] ) => {
165+ private getFieldEntitiesForNamePathList = ( nameList ?: NamePath [ ] ) => {
166+ if ( ! nameList ) {
167+ return this . getFieldEntities ( true ) ;
168+ }
169+ const cache = this . getFieldsMap ( true ) ;
170+ return nameList . map ( name => {
171+ const namePath = getNamePath ( name ) ;
172+ return cache . get ( namePath ) ;
173+ } ) ;
174+ } ;
175+
176+ private getFieldsValue = (
177+ nameList ?: NamePath [ ] ,
178+ filterFunc ?: ( meta : Meta ) => boolean ,
179+ ) => {
165180 this . warningUnhooked ( ) ;
166181
167- if ( ! nameList ) {
182+ if ( ! nameList && ! filterFunc ) {
168183 return this . store ;
169184 }
185+ if ( ! filterFunc ) {
186+ return cloneByNamePathList ( this . store , nameList . map ( getNamePath ) ) ;
187+ }
170188
171- return cloneByNamePathList ( this . store , nameList . map ( getNamePath ) ) ;
189+ const fieldEntities = this . getFieldEntitiesForNamePathList ( nameList ) ;
190+
191+ const filteredNameList : NamePath [ ] = [ ] ;
192+ fieldEntities . forEach ( ( field : FieldEntity ) => {
193+ const namePath = field . getNamePath ( ) ;
194+ const meta = field . getMeta ( ) ;
195+ if ( filterFunc ( meta ) ) {
196+ filteredNameList . push ( namePath ) ;
197+ }
198+ } ) ;
199+
200+ return cloneByNamePathList ( this . store , filteredNameList . map ( getNamePath ) ) ;
172201 } ;
173202
174203 private getFieldValue = ( name : NamePath ) => {
@@ -181,16 +210,7 @@ export class FormStore {
181210 private getFieldsError = ( nameList ?: NamePath [ ] ) => {
182211 this . warningUnhooked ( ) ;
183212
184- let fieldEntities = this . getFieldEntities ( true ) ;
185-
186- if ( nameList ) {
187- const cache = this . getFieldsMap ( true ) ;
188-
189- fieldEntities = nameList . map ( name => {
190- const namePath = getNamePath ( name ) ;
191- return cache . get ( namePath ) ;
192- } ) ;
193- }
213+ const fieldEntities = this . getFieldEntitiesForNamePathList ( nameList ) ;
194214
195215 return fieldEntities . map ( ( entity , index ) => {
196216 if ( entity ) {
0 commit comments