Skip to content

Commit da3d517

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
DateBox: Fix error on value change when empty string is set as initial value (T1301310) (#30593)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 28ee42f commit da3d517

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

packages/devextreme/js/__internal/ui/calendar/m_calendar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class Calendar<
283283
return 'number';
284284
}
285285

286-
if (!isString(value)) {
286+
if (!isString(value) || value === '') {
287287
return;
288288
}
289289

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ class DateBox extends DropDownEditor<DateBoxBaseProperties> {
758758
}
759759

760760
_getSerializationFormat() {
761-
const value = this.option('value');
761+
const { value } = this.option();
762762

763763
if (this.option('dateSerializationFormat') && config().forceIsoDateParsing) {
764764
return this.option('dateSerializationFormat');
@@ -768,7 +768,7 @@ class DateBox extends DropDownEditor<DateBoxBaseProperties> {
768768
return 'number';
769769
}
770770

771-
if (!isString(value)) {
771+
if (!isString(value) || value === '') {
772772
return;
773773
}
774774

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,14 +2239,14 @@ QUnit.module('datebox w/ calendar', {
22392239
assert.deepEqual(this.fixture.input.val(), dateLocalization.format(date, this.fixture.format));
22402240
});
22412241

2242-
QUnit.test('DateBox must pass value to calendar correctly if value is empty string', function(assert) {
2242+
QUnit.test('DateBox should pass empty string value to calendar if value is empty string', function(assert) {
22432243
this.reinitFixture({
22442244
value: '',
22452245
pickerType: 'calendar',
22462246
opened: true
22472247
});
22482248

2249-
assert.equal(this.fixture.dateBox._strategy._widget.option('value'), null, 'value is correctly');
2249+
assert.equal(this.fixture.dateBox._strategy._widget.option('value'), '', 'value is equal to empty string');
22502250
});
22512251

22522252
QUnit.test('DateBox must show the calendar with a proper date selected', function(assert) {
@@ -6184,6 +6184,33 @@ QUnit.module('DateBox number and string value support', {
61846184
assert.ok(true, 'there is no error');
61856185
}
61866186
});
6187+
6188+
[true, false].forEach(isRuntime => {
6189+
QUnit.test(`should not throw error after applying new date when empty string ${isRuntime ? 'runtime' : 'initial'} value is passed and datetime type used (T1301310)`, function(assert) {
6190+
const dateBox = $('#dateBox').dxDateBox({
6191+
value: isRuntime ? undefined : '',
6192+
type: 'datetime',
6193+
}).dxDateBox('instance');
6194+
6195+
try {
6196+
dateBox.open();
6197+
6198+
if(isRuntime) {
6199+
dateBox.option('value', '');
6200+
}
6201+
6202+
const $calendarCell = $(`.${CALENDAR_CELL_CLASS}`).eq(0);
6203+
$calendarCell.trigger('dxclick');
6204+
6205+
const $applyButton = $(dateBox.content()).parent().find(APPLY_BUTTON_SELECTOR);
6206+
$applyButton.trigger('dxclick');
6207+
6208+
assert.ok(true, 'no error');
6209+
} catch(e) {
6210+
assert.ok(false, `error thrown: ${e.message}`);
6211+
}
6212+
});
6213+
});
61876214
});
61886215

61896216
testModule('native picker', function() {

0 commit comments

Comments
 (0)