Skip to content

Commit

Permalink
NumberBox: allow to clear the selected text by pressing the decimal s…
Browse files Browse the repository at this point in the history
…eparator when the format is specified [T1199553] (#26140)

Co-authored-by: Alexander Bulychev <[email protected]>
  • Loading branch information
iBat and Alexander Bulychev authored Dec 7, 2023
1 parent cb22edf commit 9659450
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/devextreme/js/ui/number_box/number_box.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,20 @@ const NumberBoxMask = NumberBoxBase.inherit({
},

_tryParse: function(text, selection, char) {
const isTextSelected = selection.start !== selection.end;
const isWholeTextSelected = isTextSelected && selection.start === 0 && selection.end === text.length;
const decimalSeparator = number.getDecimalSeparator();

if(isWholeTextSelected && char === decimalSeparator) {
return 0;
}

const editedText = this._replaceSelectedText(text, selection, char);
const format = this._getFormatPattern();
const isTextSelected = selection.start !== selection.end;

let parsedValue = this._getParsedValue(editedText, format);
const maxPrecision = !format.parser && this._getPrecisionLimits(editedText).max;
const isValueChanged = parsedValue !== this._parsedValue;
const decimalSeparator = number.getDecimalSeparator();

const isDecimalPointRestricted = char === decimalSeparator && maxPrecision === 0;
const isUselessCharRestricted = !isTextSelected && !isValueChanged && char !== MINUS && !this._isValueIncomplete(editedText) && this._isStub(char);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,19 @@ QUnit.module('format: fixed point format', moduleConfig, () => {

assert.strictEqual(this.instance.option('text'), '4.65');
});

QUnit.test('pressing "." should clear selected text if it contains a decimal separator (T1199553)', function(assert) {
this.instance.option({
format: '0#.00',
value: 123.45
});

this.keyboard
.caret({ start: 0, end: 6 })
.type('.');

assert.strictEqual(this.input.val(), '0.00', 'mask value is cleared');
});
});

QUnit.module('format: minimum and maximum', moduleConfig, () => {
Expand Down

0 comments on commit 9659450

Please sign in to comment.