Skip to content

Commit 1dbe4ca

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
DateBox: Fix value update validation when useMaskBehavior is used (T1296990) (DevExpress#30271)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 8cf68d4 commit 1dbe4ca

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ const DateBoxMask = DateBoxBase.inherit({
482482
const limits = this._getActivePartLimits();
483483
const maxLimitLength = String(limits.max).length;
484484

485+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
485486
return ((zeroes && zeroes[0] || '') + String(value)).substr(-maxLimitLength);
486487
},
487488

@@ -514,12 +515,17 @@ const DateBoxMask = DateBoxBase.inherit({
514515

515516
_saveMaskValue() {
516517
const value = this._maskValue && new Date(this._maskValue);
517-
if (value && this.option('type') === 'date') {
518+
const { type } = this.option();
519+
520+
if (value && type === 'date') {
518521
value.setHours(0, 0, 0, 0);
519522
}
520523

521524
this._initialMaskValue = new Date(value);
522-
this.dateOption('value', value);
525+
526+
if (this._applyInternalValidation(value).isValid) {
527+
this.dateOption('value', value);
528+
}
523529
},
524530

525531
_revertChanges() {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,22 @@ module('Options changed', setupModule, () => {
15781578
});
15791579

15801580
module('Regression', () => {
1581+
QUnit.test('onValueChanged should not be fired when input is invalid and useMaskBehavior is enabled (T1296990)', function(assert) {
1582+
const valueChangedHandler = sinon.spy();
1583+
1584+
const $element = $('#dateBox').dxDateBox({
1585+
useMaskBehavior: true,
1586+
onValueChanged: valueChangedHandler,
1587+
max: new Date('07/02/2025'),
1588+
});
1589+
1590+
const $input = $element.find('.dx-texteditor-input');
1591+
1592+
$input.val('10/10/2025').change();
1593+
1594+
assert.strictEqual(valueChangedHandler.callCount, 0, 'onValueChanged is not fired');
1595+
});
1596+
15811597
QUnit.test('should paste text if value was not initialized (T715236)', function(assert) {
15821598
const $input = $('#dateBox')
15831599
.dxDateBox({

0 commit comments

Comments
 (0)