From aaac85452aea36e2b7f888d5b723d50648e88510 Mon Sep 17 00:00:00 2001 From: WilliamAguera Date: Fri, 1 Nov 2019 14:32:10 -0300 Subject: [PATCH] feat(modal-smart-form): create property to set form values on open when it with insert action. --- projects/truly-ui/src/components/form/form.ts | 21 ++++++++++++++++--- .../modal/classes/modal-smart-form.ts | 1 + .../interfaces/modal-smart-form-config.ts | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) 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;