Skip to content

Commit fb210ae

Browse files
committed
Merge pull request jquery#353 from kborchers/bug_7043
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
2 parents 4bdbab9 + abf8330 commit fb210ae

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

themes/base/jquery.ui.datepicker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; }
4040
.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; }
4141
.ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; }
42-
.ui-datepicker-row-break { clear:both; width:100%; }
42+
.ui-datepicker-row-break { clear:both; width:100%; font-size:0em; }
4343

4444
/* RTL support */
4545
.ui-datepicker-rtl { direction: rtl; }

ui/jquery.ui.datepicker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ function Datepicker() {
115115
$.extend(Datepicker.prototype, {
116116
/* Class name added to elements to indicate already configured with a date picker. */
117117
markerClassName: 'hasDatepicker',
118+
119+
//Keep track of the maximum number of rows displayed (see #7043)
120+
maxRows: 4,
118121

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

0 commit comments

Comments
 (0)