Skip to content

Commit 0577c89

Browse files
authored
Merge pull request #363 from rottaran/ticket_296_datepicker
use HTML5 date and datetime-local inputs with jquery as fallback
2 parents bb29b5a + b987ff3 commit 0577c89

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

script/EntryEditor.js

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

1616
/**
17-
* Attach datepicker to date types
17+
* Attach datepicker to date types, if lacking HTML5 support.
1818
*/
19-
$form.find('input.struct_date').datepicker({
20-
dateFormat: 'yy-mm-dd'
19+
var ftypetext = function() { return this.type === 'text'; };
20+
$form.find('input.struct_date').filter(ftypetext).datepicker({
21+
dateFormat: 'yyyy-mm-dd',
22+
changeYear: true,
2123
});
2224

2325
/**
24-
* Attach datepicker to datetype types, keeps time part
26+
* Attach datepicker to datetype types, keeps time part.
27+
* Only if browser does not support HTML5 datetime-local input.
2528
*/
26-
$form.find('input.struct_datetime').datepicker({
27-
dateFormat: 'yy-mm-dd',
29+
$form.find('input.struct_datetime').filter(ftypetext).datepicker({
30+
dateFormat: 'yyyy-mm-dd',
31+
changeYear: true,
2832
onSelect: function (date, inst) {
2933
var $input = jQuery(this);
3034
var both = inst.lastVal.split(' ', 2);

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)