From d86dc7b61ac4cc70fb28393da65bbc8cc5480921 Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:58:24 +0200 Subject: [PATCH] fix(int-value): fix int-value validation (DEV-1277) (#815) * fix(int-value): fix int-value validation * chore(int-value): replace magic number with a more clear const --- .../resource/values/int-value/int-value.component.html | 2 +- .../resource/values/int-value/int-value.component.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/workspace/resource/values/int-value/int-value.component.html b/src/app/workspace/resource/values/int-value/int-value.component.html index 5e2ca0b6c1..8c026bb215 100644 --- a/src/app/workspace/resource/values/int-value/int-value.component.html +++ b/src/app/workspace/resource/values/int-value/int-value.component.html @@ -5,7 +5,7 @@ - + New value must be different than the current value. diff --git a/src/app/workspace/resource/values/int-value/int-value.component.ts b/src/app/workspace/resource/values/int-value/int-value.component.ts index 143d3574f1..81aede532f 100644 --- a/src/app/workspace/resource/values/int-value/int-value.component.ts +++ b/src/app/workspace/resource/values/int-value/int-value.component.ts @@ -9,6 +9,8 @@ import { ValueErrorStateMatcher } from '../value-error-state-matcher'; // https://stackoverflow.com/questions/45661010/dynamic-nested-reactive-form-expressionchangedafterithasbeencheckederror const resolvedPromise = Promise.resolve(null); +const DECIMAL_VALUE = 10; + @Component({ selector: 'app-int-value', templateUrl: './int-value.component.html', @@ -87,7 +89,7 @@ export class IntValueComponent extends BaseValueDirective implements OnInit, OnC const newIntValue = new CreateIntValue(); - newIntValue.int = this.valueFormControl.value; + newIntValue.int = parseInt(this.valueFormControl.value, DECIMAL_VALUE); if (this.commentFormControl.value !== null && this.commentFormControl.value !== '') { newIntValue.valueHasComment = this.commentFormControl.value; @@ -105,7 +107,7 @@ export class IntValueComponent extends BaseValueDirective implements OnInit, OnC updatedIntValue.id = this.displayValue.id; - updatedIntValue.int = this.valueFormControl.value; + updatedIntValue.int = parseInt(this.valueFormControl.value, DECIMAL_VALUE); // add the submitted comment to updatedIntValue only if user has added a comment if (this.commentFormControl.value !== null && this.commentFormControl.value !== '') {