Skip to content

Commit

Permalink
Merge pull request #353 from kborchers/bug_7043
Browse files Browse the repository at this point in the history
Datepicker: Calculate the max number of rows necessary when displaying months. Fixes #7043 - Datepicker: Using multiple months always renders 6 rows of dates even if only 5 are needed
  • Loading branch information
scottgonzalez committed Jun 16, 2011
2 parents 4bdbab9 + abf8330 commit fb210ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion themes/base/jquery.ui.datepicker.css
Expand Up @@ -39,7 +39,7 @@
.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; } .ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; }
.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; } .ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; }
.ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; } .ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; }
.ui-datepicker-row-break { clear:both; width:100%; } .ui-datepicker-row-break { clear:both; width:100%; font-size:0em; }


/* RTL support */ /* RTL support */
.ui-datepicker-rtl { direction: rtl; } .ui-datepicker-rtl { direction: rtl; }
Expand Down
9 changes: 8 additions & 1 deletion ui/jquery.ui.datepicker.js
Expand Up @@ -115,6 +115,9 @@ function Datepicker() {
$.extend(Datepicker.prototype, { $.extend(Datepicker.prototype, {
/* Class name added to elements to indicate already configured with a date picker. */ /* Class name added to elements to indicate already configured with a date picker. */
markerClassName: 'hasDatepicker', markerClassName: 'hasDatepicker',

//Keep track of the maximum number of rows displayed (see #7043)
maxRows: 4,


/* Debug logging (if enabled). */ /* Debug logging (if enabled). */
log: function () { log: function () {
Expand Down Expand Up @@ -691,6 +694,7 @@ $.extend(Datepicker.prototype, {
/* Generate the date picker content. */ /* Generate the date picker content. */
_updateDatepicker: function(inst) { _updateDatepicker: function(inst) {
var self = this; var self = this;
self.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
var borders = $.datepicker._getBorders(inst.dpDiv); var borders = $.datepicker._getBorders(inst.dpDiv);
instActive = inst; // for delegate hover events instActive = inst; // for delegate hover events
inst.dpDiv.empty().append(this._generateHTML(inst)); inst.dpDiv.empty().append(this._generateHTML(inst));
Expand Down Expand Up @@ -1480,6 +1484,7 @@ $.extend(Datepicker.prototype, {
var html = ''; var html = '';
for (var row = 0; row < numMonths[0]; row++) { for (var row = 0; row < numMonths[0]; row++) {
var group = ''; var group = '';
this.maxRows = 4;
for (var col = 0; col < numMonths[1]; col++) { for (var col = 0; col < numMonths[1]; col++) {
var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay)); var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
var cornerClass = ' ui-corner-all'; var cornerClass = ' ui-corner-all';
Expand Down Expand Up @@ -1514,7 +1519,9 @@ $.extend(Datepicker.prototype, {
if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth) if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
inst.selectedDay = Math.min(inst.selectedDay, daysInMonth); inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7; var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
this.maxRows = numRows;
var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays)); var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
calender += '<tr>'; calender += '<tr>';
Expand Down

0 comments on commit fb210ae

Please sign in to comment.