@@ -426,25 +426,27 @@ export class FormComponent implements OnDestroy, OnInit {
426426 const metadataKeys = hasValue ( metadataFields ) ? Object . keys ( metadataFields ) : [ ] ;
427427 const formKeys = hasValue ( this . formGroup . value ) ? Object . keys ( this . formGroup . value ) : [ ] ;
428428
429- formKeys . forEach ( ( key ) => {
430- const innerObjectKeys = ( Object . keys ( this . formGroup . value [ key ] ) as any [ ] ) . map ( ( oldKey ) => oldKey . replaceAll ( '_' , '.' ) ) ;
431- const filteredKeys = innerObjectKeys . filter ( innerKey => metadataKeys . includes ( innerKey ) ) ;
432- const oldValue = this . formGroup . value [ key ] ;
433-
434- if ( filteredKeys . length > 0 ) {
435- filteredKeys . forEach ( ( oldValueKey ) => {
436- const newValue = { ...oldValue } ;
437- const formattedKey = ( oldValueKey as any ) . replaceAll ( '.' , '_' ) ;
438- const patchValue = { } ;
439-
440- newValue [ formattedKey ] = metadataFields [ oldValueKey ] [ 0 ] ;
441- patchValue [ key ] = newValue ;
442-
443- if ( ! isEqual ( oldValue [ oldValueKey ] , newValue [ oldValueKey ] ) ) {
444- this . formGroup . patchValue ( patchValue ) ;
445- }
446- } ) ;
447- }
448- } ) ;
429+ formKeys
430+ . filter ( ( key ) => isNotEmpty ( this . formGroup . value [ key ] ) )
431+ . forEach ( ( key ) => {
432+ const innerObjectKeys = ( Object . keys ( this . formGroup . value [ key ] ) as any [ ] ) . map ( ( oldKey ) => oldKey . replaceAll ( '_' , '.' ) ) ;
433+ const filteredKeys = innerObjectKeys . filter ( innerKey => metadataKeys . includes ( innerKey ) ) ;
434+ const oldValue = this . formGroup . value [ key ] ;
435+
436+ if ( filteredKeys . length > 0 ) {
437+ filteredKeys . forEach ( ( oldValueKey ) => {
438+ const newValue = { ...oldValue } ;
439+ const formattedKey = ( oldValueKey as any ) . replaceAll ( '.' , '_' ) ;
440+ const patchValue = { } ;
441+
442+ newValue [ formattedKey ] = metadataFields [ oldValueKey ] [ 0 ] ;
443+ patchValue [ key ] = newValue ;
444+
445+ if ( ! isEqual ( oldValue [ oldValueKey ] , newValue [ oldValueKey ] ) ) {
446+ this . formGroup . patchValue ( patchValue ) ;
447+ }
448+ } ) ;
449+ }
450+ } ) ;
449451 }
450452}
0 commit comments