@@ -55,9 +55,9 @@ export class FormComponent implements OnDestroy, OnInit {
5555 @Input ( ) displaySubmit = true ;
5656
5757 /**
58- * A boolean that indicate if to display form's cancel button
58+ * A boolean that indicate if to display form's reset button
5959 */
60- @Input ( ) displayCancel = true ;
60+ @Input ( ) displayReset = true ;
6161
6262 /**
6363 * A String that indicate the entity type of the item
@@ -82,7 +82,7 @@ export class FormComponent implements OnDestroy, OnInit {
8282 /**
8383 * i18n key for the cancel button
8484 */
85- @Input ( ) cancelLabel = 'form.cancel ' ;
85+ @Input ( ) resetLabel = 'form.reset ' ;
8686
8787 /**
8888 * An array of DynamicFormControlModel type
@@ -350,7 +350,6 @@ export class FormComponent implements OnDestroy, OnInit {
350350 removeItem ( $event , arrayContext : DynamicFormArrayModel , index : number ) : void {
351351 const formArrayControl = this . formGroup . get ( this . formBuilderService . getPath ( arrayContext ) ) as UntypedFormArray ;
352352 const event = this . getEvent ( $event , arrayContext , index , 'remove' ) ;
353- console . log ( formArrayControl , event ) ;
354353 if ( this . formBuilderService . isQualdropGroup ( event . model as DynamicFormControlModel ) || this . isInlineGroupForm ) {
355354 // In case of qualdrop value or inline-group remove event must be dispatched before removing the control from array
356355 this . removeArrayItem . emit ( event ) ;
@@ -434,25 +433,27 @@ export class FormComponent implements OnDestroy, OnInit {
434433 const metadataKeys = hasValue ( metadataFields ) ? Object . keys ( metadataFields ) : [ ] ;
435434 const formKeys = hasValue ( this . formGroup . value ) ? Object . keys ( this . formGroup . value ) . map ( key => key . replace ( '_array' , '' ) ) : [ ] ;
436435
437- formKeys . forEach ( ( key ) => {
438- const innerObjectKeys = ( Object . keys ( this . formGroup . value [ key ] ?? { } ) as any [ ] ) . map ( ( oldKey ) => oldKey . replaceAll ( '_' , '.' ) ) ;
439- const filteredKeys = innerObjectKeys . filter ( innerKey => metadataKeys . includes ( innerKey ) ) ;
440- const oldValue = this . formGroup . value [ key ] ;
441-
442- if ( filteredKeys . length > 0 ) {
443- filteredKeys . forEach ( ( oldValueKey ) => {
444- const newValue = { ...oldValue } ;
445- const formattedKey = ( oldValueKey as any ) . replaceAll ( '.' , '_' ) ;
446- const patchValue = { } ;
447-
448- newValue [ formattedKey ] = metadataFields [ oldValueKey ] [ 0 ] ;
449- patchValue [ key ] = newValue ;
450-
451- if ( ! isEqual ( oldValue [ oldValueKey ] , newValue [ oldValueKey ] ) ) {
452- this . formGroup . patchValue ( patchValue ) ;
453- }
454- } ) ;
455- }
436+ formKeys
437+ . filter ( ( key ) => isNotEmpty ( this . formGroup . value [ key ] ) )
438+ . forEach ( ( key ) => {
439+ const innerObjectKeys = ( Object . keys ( this . formGroup . value [ key ] ?? { } ) as any [ ] ) . map ( ( oldKey ) => oldKey . replaceAll ( '_' , '.' ) ) ;
440+ const filteredKeys = innerObjectKeys . filter ( innerKey => metadataKeys . includes ( innerKey ) ) ;
441+ const oldValue = this . formGroup . value [ key ] ;
442+
443+ if ( filteredKeys . length > 0 ) {
444+ filteredKeys . forEach ( ( oldValueKey ) => {
445+ const newValue = { ...oldValue } ;
446+ const formattedKey = ( oldValueKey as any ) . replaceAll ( '.' , '_' ) ;
447+ const patchValue = { } ;
448+
449+ newValue [ formattedKey ] = metadataFields [ oldValueKey ] [ 0 ] ;
450+ patchValue [ key ] = newValue ;
451+
452+ if ( ! isEqual ( oldValue [ oldValueKey ] , newValue [ oldValueKey ] ) ) {
453+ this . formGroup . patchValue ( patchValue ) ;
454+ }
455+ } ) ;
456+ }
456457 } ) ;
457458 }
458459}
0 commit comments