Skip to content

Commit

Permalink
feat(modal-smart-form): create property to set form values on open wh…
Browse files Browse the repository at this point in the history
…en it with insert action.
  • Loading branch information
WilliamAguera committed Nov 1, 2019
1 parent feaf475 commit aaac854
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
21 changes: 18 additions & 3 deletions projects/truly-ui/src/components/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SmartFormConfiguration implements ModalFormConfig {
executeAction;
identifier;
dataForm?;
initialDataForm?;
unique?;
deleteConfirmationMessage?;
recordNotFoundMessage?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ModalFormConfig {
identifier: string;
unique?: boolean;
dataForm?: Object;
initialDataForm?: Object;
deleteConfirmationMessage?: string;
recordNotFoundMessage?: string;
parentElement?: ElementRef;
Expand Down

0 comments on commit aaac854

Please sign in to comment.