Opened 13 years ago

Last modified 9 years ago

#6225 open bug

Datepicker: Inline datepicker and showCurrentAtPos

Reported by: richelle Owned by:
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.8.5
Keywords: Cc:
Blocked by: Blocking:


Using an inline datepicker which displays several months and specifying showCurrentAtPos is not working correctly.

When you click on a date (doesn't matter which month) it moves all months back as many steps as you've specified for showCurrentAtPos.

Say, I have set numberOfMonths = 3 and showCurrentAtPos = 2, if I click any date the months displayed will move 2 months back (so if Aug, Sep, Oct are displayed, I click on any day, the months jump back so that now Jun, Jul, Aug are displayed). If showCurrentAtPos is set to 1, after clicking on a date, the calendars move back 1 month.

$('#dp').datepicker({numberOfMonths: 3, showCurrentAtPos: 2});

Change History (10)

comment:1 Changed 13 years ago by sergik

Hi all. I've fixed this issue in my project.

       /* Action for selecting a new month/year. */
	_selectMonthYear: function(id, select, period) {
		var target = $(id);
		var inst = this._getInst(target[0]);
		inst._selectingMonthYear = false;
		inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
		inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
		/*Fix line */
                if (period == 'Y'){inst['drawMonth'] = parseInt(inst['drawMonth'],10) + this._get(inst, 'showCurrentAtPos'); }

comment:2 Changed 12 years ago by lesc

The fix from sergik above didn't work for me, as the _selectMonthYear method isn't fired when a date is selected (only from the dropdowns as far as I could tell). It appears that the calculation for moving the month location worked out every time the date is selected as well as when it's first drawn.

I've managed to get it working on mine by a quick (and probably dirty) fix, that passes a variable through to the _updateDatePicker, then _generateHTML methods so that it doesn't do the calculation on the clicking.

I would try and get this sorted cleanly, tested and forked on gitHub, but I'm a bit pressed for time, and this works for now. Hope it helps someone.

On line 892 change



this._updateDatepicker(inst, true);

Then on line 660 change

_updateDatepicker: function(inst) {


_updateDatepicker: function(inst, isClicked) {

Then on line 663 change



inst.dpDiv.empty().append(this._generateHTML(inst, isClicked))

Then on line 1353 change

_generateHTML: function(inst) {


_generateHTML: function(inst, isClicked) {

Then finally on line 1369 change

var drawMonth = inst.drawMonth - showCurrentAtPos;


var drawMonth = isClicked ? inst.drawMonth : (inst.drawMonth - showCurrentAtPos);

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

Milestone: TBD1.11.0

comment:5 Changed 11 years ago by mikesherov

Status: newopen

comment:6 Changed 11 years ago by mikesherov

#6733 is a duplicate of this ticket.

comment:7 Changed 10 years ago by tj.vantoll

Summary: Inline datepicker and showCurrentAtPosDatepicker: Inline datepicker and showCurrentAtPos

Test case against master -

comment:8 Changed 9 years ago by tj.vantoll

#9999 is a duplicate of this ticket.

comment:9 Changed 9 years ago by Scott González

Milestone: 1.11.0none

comment:10 Changed 9 years ago by Scott González

You're basically saying that you want showCurrentAtPos to be an init-only option and it shouldn't be considered after the datepicker has been rendered the first time. Is that what you're looking for?

I feel like there would need to be a different way to handle this than using showCurrentAtPos.

Note: See TracTickets for help on using tickets.