File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -499,7 +499,10 @@ export class FormStore {
499
499
// Clean up store value if preserve
500
500
const mergedPreserve = preserve !== undefined ? preserve : this . preserve ;
501
501
if ( mergedPreserve === false ) {
502
- this . store = setValue ( this . store , entity . getNamePath ( ) , undefined ) ;
502
+ const namePath = entity . getNamePath ( ) ;
503
+ if ( this . getFieldValue ( namePath ) !== undefined ) {
504
+ this . store = setValue ( this . store , namePath , undefined ) ;
505
+ }
503
506
}
504
507
} ;
505
508
} ;
Original file line number Diff line number Diff line change @@ -283,4 +283,45 @@ describe('Form.List', () => {
283
283
284
284
errorSpy . mockRestore ( ) ;
285
285
} ) ;
286
+
287
+ // https://github.com/ant-design/ant-design/issues/25584
288
+ it ( 'preserve should not break list' , async ( ) => {
289
+ let operation ;
290
+ const [ wrapper ] = generateForm (
291
+ ( fields , opt ) => {
292
+ operation = opt ;
293
+ return (
294
+ < div >
295
+ { fields . map ( field => (
296
+ < Field { ...field } >
297
+ < Input />
298
+ </ Field >
299
+ ) ) }
300
+ </ div >
301
+ ) ;
302
+ } ,
303
+ { preserve : false } ,
304
+ ) ;
305
+
306
+ // Add
307
+ act ( ( ) => {
308
+ operation . add ( ) ;
309
+ } ) ;
310
+ wrapper . update ( ) ;
311
+ expect ( wrapper . find ( Input ) ) . toHaveLength ( 1 ) ;
312
+
313
+ // Remove
314
+ act ( ( ) => {
315
+ operation . remove ( 0 ) ;
316
+ } ) ;
317
+ wrapper . update ( ) ;
318
+ expect ( wrapper . find ( Input ) ) . toHaveLength ( 0 ) ;
319
+
320
+ // Add
321
+ act ( ( ) => {
322
+ operation . add ( ) ;
323
+ } ) ;
324
+ wrapper . update ( ) ;
325
+ expect ( wrapper . find ( Input ) ) . toHaveLength ( 1 ) ;
326
+ } ) ;
286
327
} ) ;
You can’t perform that action at this time.
0 commit comments