[BUGFIX] Using datetime field with datepicker the time information gets lost
authorSteffen Kamper <info@sk-typo3.de>
Wed, 23 Mar 2011 22:24:22 +0000 (23:24 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 12 Apr 2011 21:45:28 +0000 (23:45 +0200)
As the datepicker only return date information, the time information gets lost when select a new date with datepicker.

Solution:
Add time information to selected date

Change-Id: Id0a937a3e0344ddcca840cb7e8e36c8400a09075
Resolves: #M17596
Reviewed-on: http://review.typo3.org/1248
Reviewed-by: Caspar Stuebs
Tested-by: Caspar Stuebs
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/js/extjs/tceforms.js

index 95ddc87..cd161b8 100644 (file)
@@ -44,6 +44,7 @@ TYPO3.TCEFORMS = {
                        var format = TYPO3.settings.datePickerUSmode ? TYPO3.settings.dateFormatUS : TYPO3.settings.dateFormat;
 
                        var datepicker = element.next('span');
+                       var oldValue = Date.parseDate(element.dom.value, format[index]);
 
                        // check for daterange
                        var lowerMatch = element.dom.className.match(/lower-(\d+)\b/);
@@ -54,11 +55,16 @@ TYPO3.TCEFORMS = {
                        var menu = new Ext.menu.DateMenu({
                                id:                     'p' + element.dom.id,
                                format:         format[index],
-                               value:          Date.parseDate(element.dom.value, format[index]),
+                               value:          oldValue,
                                minDate:        minDate,
                                maxDate:        maxDate,
                                handler:        function(picker, date){
                                        var relElement = Ext.getDom(picker.ownerCt.id.substring(1));
+                                       if (index === 1) {
+                                                       //datetimefield, preserve time information
+                                               date.setHours(oldValue.getHours());
+                                               date.setMinutes(oldValue.getMinutes());
+                                       }
                                        relElement.value = date.format(format[index]);
                                        if (Ext.isFunction(relElement.onchange)) {
                                                relElement.onchange.call(relElement);
@@ -79,7 +85,7 @@ TYPO3.TCEFORMS = {
                        });
                });
        },
-       
+
        convertTextareasResizable: function() {
                var textAreas = Ext.select("textarea[id^=tceforms-textarea-]");
                textAreas.each(function(element) {
@@ -100,6 +106,6 @@ TYPO3.TCEFORMS = {
                        }
                });
        }
-       
+
 }
 Ext.onReady(TYPO3.TCEFORMS.init, TYPO3.TCEFORMS);