Skip to content

Commit

Permalink
#8300 Numeric mask allows entering values less than the minimum value
Browse files Browse the repository at this point in the history
Fixes #8300
  • Loading branch information
Aleksey Novikov committed Jun 12, 2024
1 parent 6a2c5d4 commit 529f075
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mask/mask_numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions tests/mask/mask_number_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 529f075

Please sign in to comment.