@@ -178,6 +178,7 @@ export class FieldGroupApi<
178
178
store : Derived < FieldGroupState < TFieldGroupData > >
179
179
180
180
get state ( ) {
181
+ // this.store.values e.g {phone: '', fullName: ''}
181
182
return this . store . state
182
183
}
183
184
@@ -347,6 +348,17 @@ export class FieldGroupApi<
347
348
return this . form . deleteField ( this . getFormFieldName ( field ) )
348
349
}
349
350
351
+ /**
352
+ * Delete all fields and their subfields.
353
+ */
354
+ deleteAllFields = ( ) => {
355
+ const fieldGroupKeys = Object . keys ( this . state . values || { } )
356
+
357
+ fieldGroupKeys . forEach ( ( key ) => {
358
+ this . deleteField ( key )
359
+ } )
360
+ }
361
+
350
362
/**
351
363
* Pushes a value into an array field.
352
364
*/
@@ -409,6 +421,14 @@ export class FieldGroupApi<
409
421
)
410
422
}
411
423
424
+ replaceAllFields = ( newValues : TFieldGroupData ) => {
425
+ this . deleteAllFields ( )
426
+
427
+ Object . entries ( newValues || { } ) . forEach ( ( [ field , value ] ) => {
428
+ this . setFieldValue ( field , value as never )
429
+ } )
430
+ }
431
+
412
432
/**
413
433
* Removes a value from an array field at the specified index.
414
434
*/
@@ -470,6 +490,17 @@ export class FieldGroupApi<
470
490
return this . form . resetField ( this . getFormFieldName ( field ) )
471
491
}
472
492
493
+ /**
494
+ * Resets all fields values and meta to default state
495
+ */
496
+ resetAllFields = ( ) => {
497
+ const fieldGroupKeys = Object . keys ( this . state . values || { } )
498
+
499
+ fieldGroupKeys . forEach ( ( key ) => {
500
+ this . resetField ( key )
501
+ } )
502
+ }
503
+
473
504
validateAllFields = ( cause : ValidationCause ) =>
474
505
this . form . validateAllFields ( cause )
475
506
}
0 commit comments