Skip to content

Commit 34f483d

Browse files
committed
use HTML5 date and datetime-local inputs with jquery as fallback, make the year easier to edit
1 parent bb29b5a commit 34f483d

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

script/EntryEditor.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,39 @@ var EntryEditor = function($form) {
1414
$form.find('.struct .hashint').tooltip();
1515

1616
/**
17-
* Attach datepicker to date types
17+
* Attach datepicker to date types.
18+
* Only if browser does not support HTML5 date input.
1819
*/
19-
$form.find('input.struct_date').datepicker({
20-
dateFormat: 'yy-mm-dd'
21-
});
20+
var testelem = document.createElement('input');
21+
testelem.setAttribute("type", "date");
22+
if (testelem.type === "text") {
23+
$form.find('input.struct_date').datepicker({
24+
dateFormat: 'yyyy-mm-dd',
25+
changeYear: true,
26+
});
27+
}
2228

2329
/**
24-
* Attach datepicker to datetype types, keeps time part
30+
* Attach datepicker to datetype types, keeps time part.
31+
* Only if browser does not support HTML5 datetime-local input.
2532
*/
26-
$form.find('input.struct_datetime').datepicker({
27-
dateFormat: 'yy-mm-dd',
28-
onSelect: function (date, inst) {
29-
var $input = jQuery(this);
30-
var both = inst.lastVal.split(' ', 2);
31-
if (both.length == 2) {
32-
date += ' ' + both[1];
33-
} else {
34-
date += ' 00:00:00';
33+
testelem.setAttribute("type", "datetime-local");
34+
if (testelem.type === "text") {
35+
$form.find('input.struct_datetime').datepicker({
36+
dateFormat: 'yyyy-mm-dd',
37+
changeYear: true,
38+
onSelect: function (date, inst) {
39+
var $input = jQuery(this);
40+
var both = inst.lastVal.split(' ', 2);
41+
if (both.length == 2) {
42+
date += ' ' + both[1];
43+
} else {
44+
date += ' 00:00:00';
45+
}
46+
$input.val(date);
3547
}
36-
$input.val(date);
37-
}
38-
});
48+
});
49+
}
3950

4051
/**
4152
* Attach image dialog to image types

types/Date.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function valueEditor($name, $rawvalue, $htmlID) {
4848
'name' => $name,
4949
'value' => $rawvalue,
5050
'class' => 'struct_date',
51+
'type' => 'date', // HTML5 date picker
5152
'id' => $htmlID,
5253
);
5354
$attributes = buildAttributes($params, true);

types/DateTime.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function valueEditor($name, $rawvalue, $htmlID) {
4646
'name' => $name,
4747
'value' => $rawvalue,
4848
'class' => 'struct_datetime',
49+
'type' => 'datetime-local', // HTML5 datetime picker
4950
'id' => $htmlID,
5051
);
5152
$attributes = buildAttributes($params, true);

0 commit comments

Comments
 (0)