Opened 9 years ago

Closed 7 years ago

Last modified 4 years ago

#7288 closed bug (worksforme)

DatePicker jumps months when going to the Next/Previous month

Reported by: niko1312 Owned by:
Priority: minor Milestone: 1.11.0
Component: ui.datepicker Version: 1.8.11
Keywords: Cc:
Blocked by: Blocking:

Description

OS: Windows 7 Professional, 64 bit Browser: Google Chrome - 10.0.648.204 jQuery UI: 1.8.11 jQuery: 1.5.1

I use this code to enable the date picker for an Yearly calendar:

<script> $(function() {

$( "#datepicker" ).datepicker({

firstDay: 1, stepMonths: 12, showCurrentAtPos: new Date().getMonth(),

numberOfMonths: [3, 4],

dateFormat: "mm-dd-yy"

}); }); </script>

</head> <body> <div class="demo"> Date: <div id="datepicker"></div> </div>

After the page load the first month is Jan,2011. When changing for the next year and/or previous year, the months are jumping - the first month is not January 2011, but e.g. April 2011, etc Expected: After moving years forth and behind the months should stay as they were initially displayed.

Possible solution: I added this block of code to the 1399 line of thejquery.ui.datepicker.js file:

if (inst.drawMonth == showCurrentAtPos){

drawMonth = inst.drawMonth - showCurrentAtPos;

} else{

drawMonth = inst.drawMonth;

}

And no jumping was seen for my situation.

Change History (5)

comment:1 Changed 7 years ago by Scott González

Milestone: 1.9.01.11.0

comment:2 Changed 7 years ago by mikesherov

Resolution: worksforme
Status: newclosed

Thanks for taking the time to contribute to the jQuery UI project! I can no longer reproduce the issue using the latest jQuery and jQuery UI. http://jsfiddle.net/xFtfn/embedded/result/

If you can still reproduce it, please feel free to reopen the bug. Thanks!

comment:3 Changed 6 years ago by cfalletta

Hi,

I've run into this jumping problem and struggled to find what was causing this jump since it seems to have been fixed.

It appears that i was updating the "minDate" in the "onSelect" method of my datepicker : $(this).datepicker("option", "minDate", dateText);

-> this caused the unfortunate jump...

A solution i found was to comment this line in jquery-ui _optionDatepicker: function(target, name, value) {

... this._setDate(inst, date);

}

I don't know what it does... But everything is working ok when i comment this line... If i upgrade jquery later on, i wouldn't like my change to be overriden so i'll leave you guys handle this remaining bug and hope it will be fixed in the upcoming releases.

comment:4 Changed 6 years ago by Scott González

Please file a new ticket and provide a reduced test case that shows the problem.

comment:5 Changed 4 years ago by syryos2

I found a solution and patched the jquery-ui.js in basically two code lines in the datepicker subroutines _adjustDate() and _updateDatepicker() (see also cross-posting in http://bugs.jqueryui.com/ticket/9923#comment:4 ):

--- jquery-ui.orig.js	2015-11-23 20:04:52.000000000 +0100
+++ jquery-ui.js	2015-11-23 17:56:37.987111191 +0100
@@ -8815,6 +8815,8 @@
 				origyearshtml = inst.yearshtml = null;
 			}, 0);
 		}
+		// FIX BUG http://bugs.jqueryui.com/ticket/7288
+		inst.drawMonth += this._get(inst, "showCurrentAtPos");
 	},
 
 	// #6694 - don't focus the input if it's already focused
@@ -8940,9 +8942,14 @@
 		if (this._isDisabledDatepicker(target[0])) {
 			return;
 		}
+		// FIX BUG http://bugs.jqueryui.com/ticket/7288
+		/*
 		this._adjustInstDate(inst, offset +
 			(period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
 			period);
+		*/
+		this._adjustInstDate(inst, offset, period);
+
 		this._updateDatepicker(inst);
 	},
 
Note: See TracTickets for help on using tickets.