diff --git a/frontend/src/app/components/action-plan/action-plan.component.ts b/frontend/src/app/components/action-plan/action-plan.component.ts index aad9c1dff8..b48c593cb6 100644 --- a/frontend/src/app/components/action-plan/action-plan.component.ts +++ b/frontend/src/app/components/action-plan/action-plan.component.ts @@ -4,7 +4,17 @@ import { Action } from '../../shared/types/model/action'; import { ActionService } from '../../services/action.service'; import { trackByFn } from '../../shared/common'; import { DialogService } from '../../services/dialog.service'; -import { ControlContainer, FormArray, FormControl, FormGroup, FormGroupDirective } from '@angular/forms'; +import { AbstractControl, ControlContainer, FormArray, FormControl, FormGroup, FormGroupDirective } from '@angular/forms'; + +export type FormControlsOf = { + [P in keyof T]: AbstractControl; +}; + +export interface Item { + id: number | undefined; + item: string; + isChecked: boolean; +} @Component({ selector: 'app-action-plan', @@ -27,7 +37,7 @@ export class ActionPlanComponent implements AfterContentInit { } changeItemPosition(currentIndex: number, newIndex: number) { - const value = this.getFormControlArray().value; + const value = this.getFormControlArray().value as Item[]; moveItemInArray(value, currentIndex, newIndex); this.getFormControlArray() .setValue(value); @@ -66,10 +76,11 @@ export class ActionPlanComponent implements AfterContentInit { } addNewItem() { - const newItemControl = new FormControl(''); - const newIdControl = new FormControl(undefined); - const newFormGroup = new FormGroup({ item: newItemControl, - id: newIdControl }); + const newFormGroup = new FormGroup({ + item: new FormControl(''), + id: new FormControl(undefined), + isChecked: new FormControl(false) + } as FormControlsOf); this.getFormControlArray() ?.push(newFormGroup); } @@ -85,13 +96,15 @@ export class ActionPlanComponent implements AfterContentInit { protected readonly trackByFn = trackByFn; getFormControlArray() { - return this.parentF.form?.get(this.formArrayName) as FormArray; + return this.parentF.form?.get(this.formArrayName) as FormArray>>; } ngAfterContentInit(): void { this.form = this.parentF.form; - this.addNewItem(); - this.addNewItem(); - this.addNewItem(); + if (this.getFormControlArray()?.length === 0) { + this.addNewItem(); + this.addNewItem(); + this.addNewItem(); + } } } diff --git a/frontend/src/app/components/checkin/check-in-form/check-in-form.component.html b/frontend/src/app/components/checkin/check-in-form/check-in-form.component.html index 01f91d9e59..b8394b8b2e 100644 --- a/frontend/src/app/components/checkin/check-in-form/check-in-form.component.html +++ b/frontend/src/app/components/checkin/check-in-form/check-in-form.component.html @@ -48,7 +48,7 @@ - +