From a307992375c1b67a930d6c9c5b497828ed6cad8f Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Tue, 25 Aug 2015 17:47:13 +0200 Subject: [PATCH] Calendar: Fix weekday name jumping when using numberOfMonths option Fixes weekday name jumping when clicking the last day of the last grid. Includes some basic tests for multiple month demo and this specific issue. --- tests/unit/calendar/options.js | 30 +++++++++++++++++++++++++++++- ui/widgets/calendar.js | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/unit/calendar/options.js b/tests/unit/calendar/options.js index 5af5e479e..93f199580 100644 --- a/tests/unit/calendar/options.js +++ b/tests/unit/calendar/options.js @@ -232,7 +232,35 @@ test( "min / max", function() { element .calendar( "option", { min: minDate, max: maxDate } ) .calendar( "value", "1/4/09" ); - testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > max" );}); + testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > max" ); +}); + +test( "numberOfMonths", function() { + expect( 5 ); + var date = new Date( 2015, 8 - 1, 1 ), + input = $( "#calendar" ).calendar({ + numberOfMonths: 3, + value: date + }), + container = input.calendar( "widget" ); + + equal( container.find( ".ui-calendar-group" ).length, 3, "3 calendar grids" ); + equal( + container.find( "tbody:first td[id]:first" ).attr( "id" ), + "calendar-2015-7-1", + "Correct id set for first day of first grid" + ); + equal( + container.find( "tbody:last td[id]:last" ).attr( "id" ), + "calendar-2015-9-31", + "Correct id set for last day of third grid" + ); + + // Test for jumping in weekday rendering after click on last day of last grid + equal( container.find( "thead:last th:last" ).text(), "Sa", "Before click: Last day is saturday" ); + container.find( "tbody:last td[id]:last button" ).trigger( "mousedown" ); + equal( container.find( "thead:last th:last" ).text(), "Sa", "After click: Last day is saturday" ); +}); /* // TODO: Move this to $.date, Globalize or calendar widget diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js index 947d79d8d..a9a189947 100644 --- a/ui/widgets/calendar.js +++ b/ui/widgets/calendar.js @@ -329,7 +329,7 @@ return $.widget( "ui.calendar", { var cells = "", i = 0, weekDayLength = this.viewDate.weekdays().length, - weekdays = this.date.weekdays(); + weekdays = this.viewDate.weekdays(); if ( this.options.showWeek ) { cells += "" + this._getTranslation( "weekHeader" ) + ""; -- 2.39.5