diff --git a/projects/truly-ui/src/components/form/form.ts b/projects/truly-ui/src/components/form/form.ts index 3cdbb3017..abd218711 100644 --- a/projects/truly-ui/src/components/form/form.ts +++ b/projects/truly-ui/src/components/form/form.ts @@ -189,13 +189,28 @@ export class TlForm implements OnInit, AfterViewInit, AfterContentInit, OnDestro if ( this.modalInstance.modalConfiguration && this.modalInstance.modalConfiguration.executeAction !== ActionsModal.INSERT && this.modalInstance.modalConfiguration.dataForm ) { - this.formGroup.patchValue( this.modalInstance.modalConfiguration.dataForm ); - this.markAllAsTouched( this.formGroup.controls ); - this.change.detectChanges(); + this.patchDataForm(); + } + if ( this.modalInstance.modalConfiguration && + this.modalInstance.modalConfiguration.executeAction === ActionsModal.INSERT && + this.modalInstance.modalConfiguration.initialDataForm ) { + this.patchInitialDataForm(); } } } + patchDataForm() { + this.formGroup.patchValue( this.modalInstance.modalConfiguration.dataForm ); + this.markAllAsTouched( this.formGroup.controls ); + this.change.detectChanges(); + } + + patchInitialDataForm() { + this.formGroup.patchValue( this.modalInstance.modalConfiguration.initialDataForm ); + this.markAllAsTouched( this.formGroup.controls ); + this.change.detectChanges(); + } + markAllAsTouched( controls ) { Object.keys( controls ).forEach(key => { if ( controls[key] instanceof FormGroup ) { diff --git a/projects/truly-ui/src/components/modal/classes/modal-smart-form.ts b/projects/truly-ui/src/components/modal/classes/modal-smart-form.ts index 0b86344b2..49e878d96 100644 --- a/projects/truly-ui/src/components/modal/classes/modal-smart-form.ts +++ b/projects/truly-ui/src/components/modal/classes/modal-smart-form.ts @@ -9,6 +9,7 @@ export class SmartFormConfiguration implements ModalFormConfig { executeAction; identifier; dataForm?; + initialDataForm?; unique?; deleteConfirmationMessage?; recordNotFoundMessage?; diff --git a/projects/truly-ui/src/components/modal/interfaces/modal-smart-form-config.ts b/projects/truly-ui/src/components/modal/interfaces/modal-smart-form-config.ts index 6641de869..f4933ad88 100644 --- a/projects/truly-ui/src/components/modal/interfaces/modal-smart-form-config.ts +++ b/projects/truly-ui/src/components/modal/interfaces/modal-smart-form-config.ts @@ -29,6 +29,7 @@ export interface ModalFormConfig { identifier: string; unique?: boolean; dataForm?: Object; + initialDataForm?: Object; deleteConfirmationMessage?: string; recordNotFoundMessage?: string; parentElement?: ElementRef;