Skip to content

Commit c7da7d1

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

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
@@ -2230,14 +2230,14 @@ QUnit.module('datebox w/ calendar', {
22302230
assert.deepEqual(this.fixture.input.val(), dateLocalization.format(date, this.fixture.format));
22312231
});
22322232

2233-
QUnit.test('DateBox must pass value to calendar correctly if value is empty string', function(assert) {
2233+
QUnit.test('DateBox should pass empty string value to calendar if value is empty string', function(assert) {
22342234
this.reinitFixture({
22352235
value: '',
22362236
pickerType: 'calendar',
22372237
opened: true
22382238
});
22392239

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

22432243
QUnit.test('DateBox must show the calendar with a proper date selected', function(assert) {
@@ -6164,6 +6164,33 @@ QUnit.module('DateBox number and string value support', {
61646164
assert.ok(true, 'there is no error');
61656165
}
61666166
});
6167+
6168+
[true, false].forEach(isRuntime => {
6169+
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) {
6170+
const dateBox = $('#dateBox').dxDateBox({
6171+
value: isRuntime ? undefined : '',
6172+
type: 'datetime',
6173+
}).dxDateBox('instance');
6174+
6175+
try {
6176+
dateBox.open();
6177+
6178+
if(isRuntime) {
6179+
dateBox.option('value', '');
6180+
}
6181+
6182+
const $calendarCell = $(`.${CALENDAR_CELL_CLASS}`).eq(0);
6183+
$calendarCell.trigger('dxclick');
6184+
6185+
const $applyButton = $(dateBox.content()).parent().find(APPLY_BUTTON_SELECTOR);
6186+
$applyButton.trigger('dxclick');
6187+
6188+
assert.ok(true, 'no error');
6189+
} catch(e) {
6190+
assert.ok(false, `error thrown: ${e.message}`);
6191+
}
6192+
});
6193+
});
61676194
});
61686195

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

0 commit comments

Comments
 (0)