Skip to content

Commit 57b9e9d

Browse files
kborchersscottgonzalez
authored andcommitted
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
(cherry picked from commit 1d984e7)
1 parent 4d8529c commit 57b9e9d

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 () {
@@ -680,6 +683,7 @@ $.extend(Datepicker.prototype, {
680683
/* Generate the date picker content. */
681684
_updateDatepicker: function(inst) {
682685
var self = this;
686+
self.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
683687
var borders = $.datepicker._getBorders(inst.dpDiv);
684688
instActive = inst; // for delegate hover events
685689
inst.dpDiv.empty().append(this._generateHTML(inst));
@@ -1501,7 +1505,9 @@ $.extend(Datepicker.prototype, {
15011505
if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
15021506
inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
15031507
var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
1504-
var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
1508+
var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
1509+
var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
1510+
this.maxRows = numRows;
15051511
var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
15061512
for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
15071513
calender += '<tr>';

0 commit comments

Comments
 (0)