Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions tests/unit/calendar/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,10 @@ QUnit.test( "numberOfMonths", function( assert ) {

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

// Number of month option does not work after init
this.element
.calendar( "destroy" )
.calendar( {
numberOfMonths: 3,
value: date
} );
this.element.calendar( "option", {
numberOfMonths: 3,
value: date
} );

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

// Test if using cursor to go to the next / prev month advances three month
// Focus doesn't work here so we use an additional mouse down event
this.widget.find( "tbody:first td[id]:first button" ).trigger( "mousedown" );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
this.widget.find( "button.ui-calendar-prev" ).simulate( "click" );
assert.equal( this.widget.find( ".ui-calendar-month:first" ).text(), "May",
"After move to previous month: First month is May"
);
Expand Down
14 changes: 13 additions & 1 deletion ui/widgets/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,16 @@ return $.widget( "ui.calendar", {

_setOptions: function( options ) {
var that = this,
create = false,
refresh = false,
dateAttributes = false;

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

if ( key === "numberOfMonths" ) {
create = true;
}
if ( key in that.refreshRelatedOptions ) {
refresh = true;
}
Expand All @@ -720,8 +724,16 @@ return $.widget( "ui.calendar", {
this.date.setAttributes( this._calendarDateOptions );
this.viewDate.setAttributes( this._calendarDateOptions );
}
if ( refresh ) {
if ( create || refresh ) {
this.viewDate.setTime( this.date.date().getTime() );
}
if ( create ) {
this.element.empty();
this._removeClass( this.element, "ui-calendar-multi" );
this._createCalendar();
refresh = false;
}
if ( refresh ) {
this.refresh();
}
},
Expand Down