@@ -17,6 +17,7 @@ import {
17
17
InternalFormInstance ,
18
18
ValidateErrorEntity ,
19
19
StoreValue ,
20
+ Meta ,
20
21
} from './interface' ;
21
22
import { HOOK_MARK } from './FieldContext' ;
22
23
import { allPromiseFinish } from './utils/asyncUtil' ;
@@ -161,14 +162,42 @@ export class FormStore {
161
162
return cache ;
162
163
} ;
163
164
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
+ ) => {
165
180
this . warningUnhooked ( ) ;
166
181
167
- if ( ! nameList ) {
182
+ if ( ! nameList && ! filterFunc ) {
168
183
return this . store ;
169
184
}
185
+ if ( ! filterFunc ) {
186
+ return cloneByNamePathList ( this . store , nameList . map ( getNamePath ) ) ;
187
+ }
170
188
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 ) ) ;
172
201
} ;
173
202
174
203
private getFieldValue = ( name : NamePath ) => {
@@ -181,16 +210,7 @@ export class FormStore {
181
210
private getFieldsError = ( nameList ?: NamePath [ ] ) => {
182
211
this . warningUnhooked ( ) ;
183
212
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 ) ;
194
214
195
215
return fieldEntities . map ( ( entity , index ) => {
196
216
if ( entity ) {
0 commit comments