Skip to content

Commit

Permalink
#8037 The Min mask setting prevents a value from being removed when i…
Browse files Browse the repository at this point in the history
…t is below the specified minimum value

Fixes #8037
  • Loading branch information
novikov82 committed Apr 3, 2024
1 parent 3f7684a commit dadf0d0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/mask/mask_numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class InputMaskNumeric extends InputMaskBase {
return value;
}

public validateNumber(number: INumericalComposition): boolean {
public validateNumber(number: INumericalComposition, matchWholeMask: boolean): boolean {
const min = this.min || Number.MIN_SAFE_INTEGER;
const max = this.max || Number.MAX_SAFE_INTEGER;

Expand All @@ -162,7 +162,11 @@ export class InputMaskNumeric extends InputMaskBase {
if(Number.isNaN(value)) {
return true;
}
return value >= min && value <= max;
if (!matchWholeMask) {
return value >= 0 && value <= max || value < 0 && value >= min;
} else {
return value >= min && value <= max;
}
}
return true;
}
Expand All @@ -179,7 +183,7 @@ export class InputMaskNumeric extends InputMaskBase {
const currentChar = input[inputIndex];
switch(currentChar) {
case "-": {
if(this.allowNegativeValues) {
if (this.allowNegativeValues && (this.min === undefined || this.min < 0)) {
minusCharCount++;
}
break;
Expand Down Expand Up @@ -217,6 +221,9 @@ export class InputMaskNumeric extends InputMaskBase {
public getNumberMaskedValue(src: string | number, matchWholeMask: boolean = false): string {
const input = (src === undefined || src === null) ? "" : src;
const parsedNumber = this.parseNumber(input);
if (!this.validateNumber(parsedNumber, matchWholeMask)) {
return null;
}
const displayText = this.displayNumber(parsedNumber, true, matchWholeMask);
return displayText;
}
Expand All @@ -239,7 +246,7 @@ export class InputMaskNumeric extends InputMaskBase {
const src = leftPart + rightPart;
const parsedNumber = this.parseNumber(src);

if(!this.validateNumber(parsedNumber)) {
if (!this.validateNumber(parsedNumber, false)) {
return result;
}

Expand Down

0 comments on commit dadf0d0

Please sign in to comment.