@@ -28,6 +28,8 @@ import { DynamicRowGroupModel } from './builder/ds-dynamic-form-ui/models/ds-dyn
2828import {
2929 DynamicRelationGroupModel
3030} from './builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model' ;
31+ import { DynamicLinkModel } from './builder/ds-dynamic-form-ui/models/ds-dynamic-link.model' ;
32+ import { DynamicConcatModel } from './builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model' ;
3133
3234export interface MetadataFields {
3335 [ key : string ] : FormFieldMetadataValueObject [ ]
@@ -53,9 +55,9 @@ export class FormComponent implements OnDestroy, OnInit {
5355 @Input ( ) displaySubmit = true ;
5456
5557 /**
56- * A boolean that indicate if to display form's reset button
58+ * A boolean that indicate if to display form's cancel button
5759 */
58- @Input ( ) displayReset = true ;
60+ @Input ( ) displayCancel = true ;
5961
6062 /**
6163 * A String that indicate the entity type of the item
@@ -78,9 +80,9 @@ export class FormComponent implements OnDestroy, OnInit {
7880 @Input ( ) submitLabel = 'form.submit' ;
7981
8082 /**
81- * i18n key for the reset button
83+ * i18n key for the cancel button
8284 */
83- @Input ( ) resetLabel = 'form.reset ' ;
85+ @Input ( ) cancelLabel = 'form.cancel ' ;
8486
8587 /**
8688 * An array of DynamicFormControlModel type
@@ -348,14 +350,20 @@ export class FormComponent implements OnDestroy, OnInit {
348350 removeItem ( $event , arrayContext : DynamicFormArrayModel , index : number ) : void {
349351 const formArrayControl = this . formGroup . get ( this . formBuilderService . getPath ( arrayContext ) ) as UntypedFormArray ;
350352 const event = this . getEvent ( $event , arrayContext , index , 'remove' ) ;
353+ console . log ( formArrayControl , event ) ;
351354 if ( this . formBuilderService . isQualdropGroup ( event . model as DynamicFormControlModel ) || this . isInlineGroupForm ) {
352355 // In case of qualdrop value or inline-group remove event must be dispatched before removing the control from array
353356 this . removeArrayItem . emit ( event ) ;
354357 }
355358 if ( index === 0 && formArrayControl . value ?. length === 1 ) {
356359 event . model = cloneDeep ( event . model ) ;
357360 const fieldId = event . model . id ;
358- formArrayControl . at ( 0 ) . get ( fieldId ) . setValue ( null ) ;
361+
362+ if ( event . model instanceof DynamicLinkModel || event . model instanceof DynamicConcatModel ) {
363+ formArrayControl . at ( 0 ) . get ( fieldId ) . reset ( ) ;
364+ } else {
365+ formArrayControl . at ( 0 ) . get ( fieldId ) . setValue ( null ) ;
366+ }
359367 } else {
360368 this . formBuilderService . removeFormArrayGroup ( index , formArrayControl , arrayContext ) ;
361369 }
@@ -424,29 +432,27 @@ export class FormComponent implements OnDestroy, OnInit {
424432
425433 private updateMetadataValue ( metadataFields : MetadataFields ) : void {
426434 const metadataKeys = hasValue ( metadataFields ) ? Object . keys ( metadataFields ) : [ ] ;
427- const formKeys = hasValue ( this . formGroup . value ) ? Object . keys ( this . formGroup . value ) : [ ] ;
428-
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- } ) ;
435+ const formKeys = hasValue ( this . formGroup . value ) ? Object . keys ( this . formGroup . value ) . map ( key => key . replace ( '_array' , '' ) ) : [ ] ;
436+
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+ }
456+ } ) ;
451457 }
452458}
0 commit comments