Skip to content

Commit

Permalink
fix(int-value): fix int-value validation (DEV-1277) (#815)
Browse files Browse the repository at this point in the history
* fix(int-value): fix int-value validation

* chore(int-value): replace magic number with a more clear const
  • Loading branch information
mdelez committed Sep 6, 2022
1 parent 375166a commit d86dc7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -5,7 +5,7 @@
<ng-template #showForm>
<span [formGroup]="form">
<mat-form-field class="large-field child-value-component" floatLabel="never">
<input matInput [formControlName]="'value'" class="value" placeholder="Int value" type="number" [errorStateMatcher]="matcher">
<input matInput [formControlName]="'value'" class="value" placeholder="Int value" [errorStateMatcher]="matcher">
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged') &&
(valueFormControl.touched || valueFormControl.dirty)">
<span class="custom-error-message">New value must be different than the current value.</span>
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand All @@ -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 !== '') {
Expand Down

0 comments on commit d86dc7b

Please sign in to comment.