Skip to content

Commit 188550f

Browse files
committed
Calendar: Make sure option numberOfMonth could be changed after creation
1 parent 00a470b commit 188550f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

tests/unit/calendar/options.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,10 @@ QUnit.test( "numberOfMonths", function( assert ) {
278278

279279
var date = new Date( 2015, 8 - 1, 1 );
280280

281-
// Number of month option does not work after init
282-
this.element
283-
.calendar( "destroy" )
284-
.calendar( {
285-
numberOfMonths: 3,
286-
value: date
287-
} );
281+
this.element.calendar( "option", {
282+
numberOfMonths: 3,
283+
value: date
284+
} );
288285

289286
assert.equal( this.widget.find( ".ui-calendar-group" ).length, 3, "3 calendar grids" );
290287
assert.equal(
@@ -304,10 +301,7 @@ QUnit.test( "numberOfMonths", function( assert ) {
304301
"After mousedown last month: Last day is Saturday"
305302
);
306303

307-
// Test if using cursor to go to the next / prev month advances three month
308-
// Focus doesn't work here so we use an additional mouse down event
309-
this.widget.find( "tbody:first td[id]:first button" ).trigger( "mousedown" );
310-
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
304+
this.widget.find( "button.ui-calendar-prev" ).simulate( "click" );
311305
assert.equal( this.widget.find( ".ui-calendar-month:first" ).text(), "May",
312306
"After move to previous month: First month is May"
313307
);

ui/widgets/calendar.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,16 @@ return $.widget( "ui.calendar", {
703703

704704
_setOptions: function( options ) {
705705
var that = this,
706+
create = false,
706707
refresh = false,
707708
dateAttributes = false;
708709

709710
$.each( options, function( key, value ) {
710711
that._setOption( key, value );
711712

713+
if ( key === "numberOfMonths" ) {
714+
create = true;
715+
}
712716
if ( key in that.refreshRelatedOptions ) {
713717
refresh = true;
714718
}
@@ -722,8 +726,16 @@ return $.widget( "ui.calendar", {
722726
this.date.setAttributes( this._calendarDateOptions );
723727
this.viewDate.setAttributes( this._calendarDateOptions );
724728
}
725-
if ( refresh ) {
729+
if ( create || refresh ) {
726730
this.viewDate.setTime( this.date.date().getTime() );
731+
}
732+
if ( create ) {
733+
this.element.empty();
734+
this._removeClass( this.element, "ui-calendar-multi" );
735+
this._createCalendar();
736+
refresh = false;
737+
}
738+
if ( refresh ) {
727739
this.refresh();
728740
}
729741
},

0 commit comments

Comments
 (0)