From 7bc4f4055cd228c5974ccbe3d4fa91e9b6a3c897 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 17 Jul 2023 17:38:25 +0300 Subject: [PATCH] Fix progress indicator in prifilled dataset form. #8764 --- .../form-progress-indication.component.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts index 3cf3158d3..cf953e754 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Input, OnInit } from '@angular/core'; +import {ChangeDetectorRef, Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service'; import { BaseComponent } from '@common/base/base.component'; @@ -9,7 +9,7 @@ import { takeUntil } from 'rxjs/operators'; templateUrl: './form-progress-indication.component.html', styleUrls: ['./form-progress-indication.component.scss'] }) -export class FormProgressIndicationComponent extends BaseComponent implements OnInit { +export class FormProgressIndicationComponent extends BaseComponent implements OnInit, OnChanges { @Input() formGroup: FormGroup; @Input() isDmpEditor: boolean; @Input() isDatasetEditor: boolean; @@ -23,6 +23,16 @@ export class FormProgressIndicationComponent extends BaseComponent implements On public value = 0; ngOnInit() { + this.init(); + } + + ngOnChanges(changes: SimpleChanges) { + if(changes.formGroup) { + this.init(); + } + } + + init() { setTimeout(() => {this.calculateValueForProgressbar();}); this.formGroup .valueChanges @@ -143,7 +153,7 @@ export class FormProgressIndicationComponent extends BaseComponent implements On countFormControlsValidForProgress(formControl: AbstractControl): number { let valueCurrent = 0; if (formControl instanceof FormControl) { - if (this.controlRequired(formControl) && this.controlEnabled(formControl) && formControl['nativeElement'] && formControl.valid) { + if (this.controlRequired(formControl) && this.controlEnabled(formControl) && formControl.valid) { valueCurrent++; } } else if (formControl instanceof FormGroup) { @@ -162,7 +172,7 @@ export class FormProgressIndicationComponent extends BaseComponent implements On countFormControlsRequiredFieldsForTotal(formControl: AbstractControl): number { let valueCurrent = 0; if (formControl instanceof FormControl) { - if (this.controlRequired(formControl) && this.controlEnabled(formControl) && formControl['nativeElement']) { + if (this.controlRequired(formControl) && this.controlEnabled(formControl)) { valueCurrent++; } } else if (formControl instanceof FormGroup) {