Bug Tracker

Ticket #1996 (closed bug: fixed)

Opened 9 months ago

Last modified 8 months ago

datepicker - next/prev with multiple months and min/max

Reported by: emielroelofsen Assigned to: kbwood
Type: bug Priority: major
Milestone: 1.2.2 Component: ui
Version: 1.2.1 Keywords: datepicker
Cc: emielroelofsen@hotmail.com Needs: Review

Description

The function _canAdjustMonth is't correct.

Example

I want to show 3 months ( numberOfMonths: 3 )
My minimum date is 2008-01-26 ( minDate: new Date(2008, 1 - 1, 26) )
My maximum date is 2008-04-27 ( minDate: new Date(2008, 4 - 1, 27) )
hideIfNoPrevNext is set to true

Because of the bug in the function _canAdjustMonth I can press the next button until juni 2008. The solution is also to calculate the numberOfMonths.

Solution

OLD FUNCTOIN

_canAdjustMonth: function(offset) {
   var date = new Date(this._selectedYear, this._selectedMonth + offset, 1);
   if (offset < 0) {
      date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
   }
   return this._isInRange(date);
},

NEW FUNCTION

_canAdjustMonth: function(offset) {
   var month = offset > 0 ?
      this._selectedMonth + offset + this._get('numberOfMonths') - 1 :
      this._selectedMonth + offset;
   var date = new Date(this._selectedYear, month, 1);
   if (offset < 0) {
      date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
   }
   return this._isInRange(date);
},

Emiel Roelofsen

Attachments

Change History

Changed 8 months ago by kbwood

  • owner set to kbwood
  • status changed from new to assigned

Changed 8 months ago by kbwood

  • summary changed from ui.datepicker.js to datepicker - next/prev with multiple months and min/max

Changed 8 months ago by kbwood

  • status changed from assigned to closed
  • resolution set to fixed

Implemented a fix that prevents non-selectable months at the end of a multiple month display (unless also constrained by the minDate).

Note: See TracTickets for help on using tickets.