From 381c1534e171f114336f7f17c8052cb2e337b5da Mon Sep 17 00:00:00 2001 From: Vineet Sharma Date: Wed, 7 Jun 2023 17:29:16 +0530 Subject: [PATCH] (fix) KH-180: Fixed the min and max validator for number inputs to validate value 0 (#52) * Fixed the min and max validator for number inputs to validate value 0 * Removed the console.logs --- .../src/form-entry/validators/max.validator.ts | 6 +++++- .../src/form-entry/validators/min.validator.ts | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/projects/ngx-formentry/src/form-entry/validators/max.validator.ts b/projects/ngx-formentry/src/form-entry/validators/max.validator.ts index 5ea89b04..b8c5976f 100644 --- a/projects/ngx-formentry/src/form-entry/validators/max.validator.ts +++ b/projects/ngx-formentry/src/form-entry/validators/max.validator.ts @@ -7,7 +7,11 @@ export class MaxValidator { return null; } - if (control.value && control.value.length !== 0) { + // Case 1: control.value is a number + // all the numbers should be passed for validation + // Case 2: control.value is not a number: + // if its empty string or null or undefined it will return false else it will pass through for validation + if (typeof control.value === 'number' || control.value) { const v: number = control.value; return v <= max ? null diff --git a/projects/ngx-formentry/src/form-entry/validators/min.validator.ts b/projects/ngx-formentry/src/form-entry/validators/min.validator.ts index 4874d746..67b097aa 100644 --- a/projects/ngx-formentry/src/form-entry/validators/min.validator.ts +++ b/projects/ngx-formentry/src/form-entry/validators/min.validator.ts @@ -6,7 +6,12 @@ export class MinValidator { if (control.hidden) { return null; } - if (control.value && control.value.length !== 0) { + + // Case 1: control.value is a number + // all the numbers should be passed for validation + // Case 2: control.value is not a number: + // if its empty string or null or undefined it will return false else it will pass through for validation + if (typeof control.value === 'number' || control.value) { const v: number = control.value; return v >= min ? null