Skip to content

Commit 218510e

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
DateBox: Fix value update validation when useMaskBehavior is used (T1296990) (DevExpress#30267)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 9628a20 commit 218510e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class DateBoxMask extends DateBoxBase {
103103
// @ts-expect-error
104104
const isNotDeletingInCalendar = this.option('opened') && e && !keysToHandleByMask.includes(normalizeKeyName(e));
105105

106-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
107106
return !this._useMaskBehavior() || isNotDeletingInCalendar || (e && e.altKey);
108107
}
109108

@@ -513,7 +512,7 @@ class DateBoxMask extends DateBoxBase {
513512
const limits = this._getActivePartLimits();
514513
const maxLimitLength = String(limits.max).length;
515514

516-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/prefer-nullish-coalescing
515+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
517516
return ((zeroes && zeroes[0] || '') + String(value)).substr(-maxLimitLength);
518517
}
519518

@@ -533,7 +532,7 @@ class DateBoxMask extends DateBoxBase {
533532

534533
_getActivePartProp(property) {
535534
// @ts-expect-error ts-error
536-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
535+
537536
if (!this._dateParts || !this._dateParts[this._activePartIndex]) {
538537
return undefined;
539538
}
@@ -549,12 +548,16 @@ class DateBoxMask extends DateBoxBase {
549548
_saveMaskValue(): void {
550549
const value = this._maskValue && new Date(this._maskValue);
551550
const { type } = this.option();
551+
552552
if (value && type === 'date') {
553553
value.setHours(0, 0, 0, 0);
554554
}
555555
// @ts-expect-error ts-error
556556
this._initialMaskValue = new Date(value);
557-
this.dateOption('value', value);
557+
558+
if (this._applyInternalValidation(value).isValid) {
559+
this.dateOption('value', value);
560+
}
558561
}
559562

560563
_revertChanges(): void {
@@ -640,7 +643,7 @@ class DateBoxMask extends DateBoxBase {
640643

641644
_isValueDirty() {
642645
const value = this.dateOption('value');
643-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
646+
644647
return (this._maskValue && this._maskValue.getTime()) !== (value && value.getTime());
645648
}
646649

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)