From a8b7035aff36bf602754c8986aa8ab46f24e90dc Mon Sep 17 00:00:00 2001 From: lotte Date: Tue, 30 Jun 2020 16:02:32 +0200 Subject: [PATCH] fixed issue with validation --- .../form/process-form.component.html | 2 +- .../form/process-form.component.spec.ts | 4 ++-- .../form/process-form.component.ts | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/app/process-page/form/process-form.component.html b/src/app/process-page/form/process-form.component.html index b587fe3943..ce6d62efec 100644 --- a/src/app/process-page/form/process-form.component.html +++ b/src/app/process-page/form/process-form.component.html @@ -16,7 +16,7 @@ -
+
{{'process.new.parameter.required.missing' | translate}}
  • {{missing}}
  • diff --git a/src/app/process-page/form/process-form.component.spec.ts b/src/app/process-page/form/process-form.component.spec.ts index 78ea5fc271..e1871fbd2b 100644 --- a/src/app/process-page/form/process-form.component.spec.ts +++ b/src/app/process-page/form/process-form.component.spec.ts @@ -15,7 +15,7 @@ import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock'; import { RequestService } from '../../core/data/request.service'; import { Router } from '@angular/router'; -describe('NewProcessComponent', () => { +describe('ProcessFormComponent', () => { let component: ProcessFormComponent; let fixture: ComponentFixture; let scriptService; @@ -80,7 +80,7 @@ describe('NewProcessComponent', () => { }); it('should call invoke on the scriptService on submit', () => { - component.submitForm({ invalid: false } as any); + component.submitForm({ controls: {} } as any); expect(scriptService.invoke).toHaveBeenCalled(); }); }); diff --git a/src/app/process-page/form/process-form.component.ts b/src/app/process-page/form/process-form.component.ts index a4066a3178..ee7d7d85d2 100644 --- a/src/app/process-page/form/process-form.component.ts +++ b/src/app/process-page/form/process-form.component.ts @@ -85,12 +85,12 @@ export class ProcessFormComponent implements OnInit { if (requestEntry.response.isSuccessful) { const title = this.translationService.get('process.new.notification.success.title'); const content = this.translationService.get('process.new.notification.success.content'); - this.notificationsService.success(title, content) + this.notificationsService.success(title, content); this.sendBack(); } else { const title = this.translationService.get('process.new.notification.error.title'); const content = this.translationService.get('process.new.notification.error.content'); - this.notificationsService.error(title, content) + this.notificationsService.error(title, content); } }) } @@ -115,16 +115,18 @@ export class ProcessFormComponent implements OnInit { * @param form The NgForm object to validate */ private validateForm(form: NgForm) { - if (form.invalid) { - Object.keys(form.controls).forEach((key) => { + let valid = true; + Object.keys(form.controls).forEach((key) => { + if (form.controls[key].invalid) { form.controls[key].markAsDirty(); - }); - return false; - } - return true; + valid = false; + } + }); + return valid; } private isRequiredMissing() { + this.missingParameters = []; const setParams: string[] = this.parameters .map((param) => param.name); const requiredParams: ScriptParameter[] = this.selectedScript.parameters.filter((param) => param.mandatory);