@@ -842,6 +842,7 @@ $.extend(Timepicker.prototype, {
842
842
843
843
this . formattedDateTime = formattedDateTime ;
844
844
845
+ var range = getSelectionRange ( this ) ;
845
846
if ( ! this . _defaults . showTimepicker ) {
846
847
this . $input . val ( this . formattedDate ) ;
847
848
} else if ( this . $altInput && this . _defaults . altFieldTimeOnly === true ) {
@@ -853,6 +854,7 @@ $.extend(Timepicker.prototype, {
853
854
} else {
854
855
this . $input . val ( formattedDateTime ) ;
855
856
}
857
+ restoreSelectionRange ( this , range ) ;
856
858
857
859
this . $input . trigger ( "change" ) ;
858
860
}
@@ -1085,10 +1087,12 @@ $.datepicker._selectDate = function (id, dateStr) {
1085
1087
tp_inst = this . _get ( inst , 'timepicker' ) ;
1086
1088
1087
1089
if ( tp_inst ) {
1090
+ var range = getSelectionRange ( inst ) ;
1088
1091
tp_inst . _limitMinMaxDateTime ( inst , true ) ;
1089
1092
inst . inline = inst . stay_open = true ;
1090
1093
//This way the onSelect handler called from calendarpicker get the full dateTime
1091
1094
this . _base_selectDate ( id , dateStr ) ;
1095
+ setSelectionRange ( inst , range ) ;
1092
1096
inst . inline = inst . stay_open = false ;
1093
1097
this . _notifyChange ( inst ) ;
1094
1098
this . _updateDatepicker ( inst ) ;
@@ -1194,11 +1198,13 @@ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
1194
1198
$ . datepicker . _gotoToday = function ( id ) {
1195
1199
var inst = this . _getInst ( $ ( id ) [ 0 ] ) ,
1196
1200
$dp = inst . dpDiv ;
1201
+ var range = getSelectionRange ( inst ) ;
1197
1202
this . _base_gotoToday ( id ) ;
1198
1203
var tp_inst = this . _get ( inst , 'timepicker' ) ;
1199
1204
selectLocalTimeZone ( tp_inst ) ;
1200
1205
var now = new Date ( ) ;
1201
1206
this . _setTime ( inst , now ) ;
1207
+ restoreSelectionRange ( this , range ) ;
1202
1208
$ ( '.ui-datepicker-today' , $dp ) . click ( ) ;
1203
1209
} ;
1204
1210
@@ -1515,6 +1521,31 @@ var selectLocalTimeZone = function(tp_inst, date)
1515
1521
}
1516
1522
} ;
1517
1523
1524
+ //#######################################################################################
1525
+ // Helper functions to retreive selection range and restore selection range
1526
+ //#######################################################################################
1527
+ var getSelectionRange = function ( tp_inst )
1528
+ {
1529
+ var range = { } ;
1530
+ range . input = {
1531
+ 'selectionStart' : tp_inst . $input . prop ( 'selectionStart' ) ,
1532
+ 'selectionEnd' : tp_inst . $input . prop ( 'selectionEnd' ) } ;
1533
+ if ( tp_inst . $altInput ) {
1534
+ range . altInput = {
1535
+ 'selectionStart' : tp_inst . $altInput . prop ( 'selectionStart' ) ,
1536
+ 'selectionEnd' : tp_inst . $altInput . prop ( 'selectionEnd' ) } ;
1537
+ }
1538
+ return range ;
1539
+ } ;
1540
+
1541
+ var restoreSelectionRange = function ( tp_inst , range )
1542
+ {
1543
+ tp_inst . $input . prop ( range . input ) ;
1544
+ if ( range . altInput !== undefined ) {
1545
+ tp_inst . $altInput . prop ( range . altInput ) ;
1546
+ }
1547
+ } ;
1548
+
1518
1549
// Input: Date Object
1519
1550
// Output: String with timezone offset, e.g. '+0100'
1520
1551
var timeZoneString = function ( date )
0 commit comments