Skip to content

Commit 0d26b7c

Browse files
DateBox: fix formatting of min/max attribute in datetime picker type (T1252602) (DevExpress#28679)
1 parent dee4aac commit 0d26b7c

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

js/ui/date_box/ui.date_box.strategy.native.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,18 @@ const NativeStrategy = DateBoxStrategy.inherit({
6565
return displayFormat || dateUtils.FORMATS_MAP[type];
6666
},
6767

68-
renderInputMinMax: function($input) {
68+
renderInputMinMax($input) {
69+
const type = this.dateBox.option('type');
70+
const defaultFormat = 'yyyy-MM-dd';
71+
const format = {
72+
datetime: 'yyyy-MM-ddTHH:mm:ss',
73+
date: defaultFormat,
74+
time: 'HH:mm:ss',
75+
}[type] ?? defaultFormat;
76+
6977
$input.attr({
70-
min: dateSerialization.serializeDate(this.dateBox.dateOption('min'), 'yyyy-MM-dd'),
71-
max: dateSerialization.serializeDate(this.dateBox.dateOption('max'), 'yyyy-MM-dd')
78+
min: dateSerialization.serializeDate(this.dateBox.dateOption('min'), format),
79+
max: dateSerialization.serializeDate(this.dateBox.dateOption('max'), format),
7280
});
7381
}
7482
});

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,46 @@ QUnit.module('datebox tests', moduleConfig, () => {
230230
}
231231
});
232232

233+
QUnit.test('Datebox should set min/max attributes to datetime input in localized datetime format (T1252602)', function(assert) {
234+
const $dateBox = $('#dateBox').dxDateBox({
235+
type: 'datetime',
236+
pickerType: 'native',
237+
value: new Date(2024, 8, 15, 16, 54, 10),
238+
min: new Date(2024, 8, 10, 16, 54, 14),
239+
max: new Date(2024, 8, 27, 16, 54, 15)
240+
});
241+
242+
const $input = $dateBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
243+
assert.equal($input.attr('min'), '2024-09-10T16:54:14', 'minimum date set correctly');
244+
assert.equal($input.attr('max'), '2024-09-27T16:54:15', 'maximum date set correctly');
245+
});
246+
247+
QUnit.test('Datebox should set min/max attributes to time input in localized time format (T1252602)', function(assert) {
248+
const $dateBox = $('#dateBox').dxDateBox({
249+
type: 'time',
250+
pickerType: 'native',
251+
value: new Date(2024, 8, 10, 16, 30),
252+
min: new Date(2024, 8, 10, 12, 0, 14),
253+
max: new Date(2024, 8, 10, 18, 0, 15)
254+
});
255+
const $input = $dateBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
256+
assert.equal($input.attr('min'), '12:00:14', 'minimum time set correctly');
257+
assert.equal($input.attr('max'), '18:00:15', 'maximum time set correctly');
258+
});
259+
260+
QUnit.test('Datebox should set min/max attributes to date input in localized date format (T1252602)', function(assert) {
261+
const $dateBox = $('#dateBox').dxDateBox({
262+
type: 'date',
263+
pickerType: 'native',
264+
value: new Date(2024, 8, 15),
265+
min: new Date(2024, 8, 10),
266+
max: new Date(2024, 8, 20)
267+
});
268+
const $input = $dateBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
269+
assert.equal($input.attr('min'), '2024-09-10', 'minimum date set correctly');
270+
assert.equal($input.attr('max'), '2024-09-20', 'maximum date set correctly');
271+
});
272+
233273
QUnit.test('T204179 - dxDateBox should not render dropDownButton only for generic device when pickerType is \'native\'', function(assert) {
234274
const $dateBox = $('#dateBox').dxDateBox({
235275
pickerType: 'native'

0 commit comments

Comments
 (0)