From 529f075b3c23d9a61adc2c71ff58fc7089d2eb25 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Wed, 12 Jun 2024 23:52:31 +0300 Subject: [PATCH] #8300 Numeric mask allows entering values less than the minimum value Fixes #8300 --- src/mask/mask_numeric.ts | 4 ++-- tests/mask/mask_number_tests.ts | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/mask/mask_numeric.ts b/src/mask/mask_numeric.ts index 47db075212..792fa1ffc4 100644 --- a/src/mask/mask_numeric.ts +++ b/src/mask/mask_numeric.ts @@ -168,10 +168,10 @@ export class InputMaskNumeric extends InputMaskBase { } if (value >= min && value <= max) return true; if (!matchWholeMask) { - if (!number.hasDecimalSeparator) { + if (!number.hasDecimalSeparator && value != 0) { let test_high = value; let test_low = value; - if (value >= 0) { + if (value > 0) { if (value + 1 > min && value <= max) return true; while (true) { test_high = test_high * 10 + 9; diff --git a/tests/mask/mask_number_tests.ts b/tests/mask/mask_number_tests.ts index 6eedf668d1..80d9f762b4 100644 --- a/tests/mask/mask_number_tests.ts +++ b/tests/mask/mask_number_tests.ts @@ -787,6 +787,10 @@ QUnit.test("numeric validateNumber: min & max - small range positive", function maskInstance.max = 7; const number: any = {}; + + number.integralPart = "0"; + assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.integralPart = "8"; assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); @@ -800,6 +804,9 @@ QUnit.test("numeric validateNumber: min & max - small range positive", function maskInstance.min = 43; maskInstance.max = 47; + number.integralPart = "0"; + assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.integralPart = "3"; assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); @@ -827,6 +834,9 @@ QUnit.test("numeric validateNumber: min & max - small range negative", function maskInstance.max = -43; maskInstance.min = -47; + number.integralPart = "0"; + assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.isNegative = true; number.integralPart = "3"; assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); @@ -885,6 +895,31 @@ QUnit.test("numeric validateNumber: min & max - small range fractial positive", number.hasDecimalSeparator = true; assert.ok(maskInstance.validateNumber(number, false), "test with dot " + maskInstance.convertNumber(number)); + number.fractionalPart = "62"; + assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.fractionalPart = "68"; + assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.fractionalPart = "63"; + assert.ok(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + number.fractionalPart = "65"; + assert.ok(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); +}); + +QUnit.test("numeric validateNumber: min & max - small range fractial positive less 1", function (assert) { + const maskInstance = new InputMaskNumeric(); + maskInstance.allowNegativeValues = true; + maskInstance.min = 0.63; + maskInstance.max = 0.67; + maskInstance.precision = 2; + + const number: any = {}; + + number.integralPart = "0"; + assert.ok(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); + + number.hasDecimalSeparator = true; + assert.ok(maskInstance.validateNumber(number, false), "test with dot " + maskInstance.convertNumber(number)); + number.fractionalPart = "62"; assert.notOk(maskInstance.validateNumber(number, false), "test " + maskInstance.convertNumber(number)); number.fractionalPart = "68";