Skip to content

Commit 1d984e7

Browse files
committed
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
1 parent 12f73d6 commit 1d984e7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ui/jquery.ui.datepicker.js

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

118121
/* Debug logging (if enabled). */
119122
log: function () {
@@ -682,6 +685,7 @@ $.extend(Datepicker.prototype, {
682685
/* Generate the date picker content. */
683686
_updateDatepicker: function(inst) {
684687
var self = this;
688+
self.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
685689
var borders = $.datepicker._getBorders(inst.dpDiv);
686690
instActive = inst; // for delegate hover events
687691
inst.dpDiv.empty().append(this._generateHTML(inst));
@@ -1505,7 +1509,9 @@ $.extend(Datepicker.prototype, {
15051509
if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
15061510
inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
15071511
var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
1508-
var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
1512+
var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
1513+
var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
1514+
this.maxRows = numRows;
15091515
var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
15101516
for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
15111517
calender += '<tr>';

0 commit comments

Comments
 (0)