Skip to content

Commit

Permalink
Merge pull request #8522 from surveyjs/bug/8501-min-max-settings-not-…
Browse files Browse the repository at this point in the history
…allow-resetting

Text field with Numeric input mask and min/max settings doesn't allow resetting / removing a value
  • Loading branch information
andrewtelnov authored Jul 8, 2024
2 parents f0c3c27 + 3748128 commit e060a2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mask/mask_numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export class InputMaskNumeric extends InputMaskBase {
const min = this.min || Number.MIN_SAFE_INTEGER;
const max = this.max || Number.MAX_SAFE_INTEGER;

if(this.min !== undefined || this.max !== undefined) {
if (this.numericalCompositionIsEmpty(number)) return true;

if (this.min !== undefined || this.max !== undefined) {
let value = this.convertNumber(number);
if(Number.isNaN(value)) {
return true;
Expand Down
10 changes: 10 additions & 0 deletions tests/mask/mask_number_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,17 @@ QUnit.test("numeric processInput: min & max - small range", function (assert) {
result = maskInstance.processInput({ insertedChars: "6", selectionStart: 1, selectionEnd: 1, prevValue: "4", inputDirection: "forward" });
assert.equal(result.value, "46", "insert 6");
assert.equal(result.caretPosition, 2, "insert 6");
});

QUnit.test("numeric processInput: doesn't allow resetting if min & max", function (assert) {
const maskInstance = new InputMaskNumeric();
maskInstance.allowNegativeValues = false;
maskInstance.min = 2;
maskInstance.max = 10;

let result = maskInstance.processInput({ insertedChars: null, prevValue: "8", selectionEnd: 1, selectionStart: 0, inputDirection: "forward" });
assert.equal(result.value, "", "clear");
assert.equal(result.caretPosition, 0, "clear");
});

QUnit.test("numeric validateNumber: min & max - small range positive", function (assert) {
Expand Down

0 comments on commit e060a2e

Please sign in to comment.