Skip to content

Commit 6db02da

Browse files
committed
Calendar: Re-introduce formatDate option
1 parent f9ba50d commit 6db02da

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

tests/unit/calendar/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ common.testWidget( "calendar", {
99
buttons: [],
1010
classes: {},
1111
disabled: false,
12+
dateFormat: { date: "short" },
1213
eachDay: $.noop,
1314
labels: {
1415
"datePickerRole": "date picker",

ui/calendar.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ return $.widget( "ui.calendar", {
3939
version: "@VERSION",
4040
options: {
4141
buttons: [],
42+
dateFormat: { date: "short" },
4243
eachDay: $.noop,
4344
labels: {
4445
"datePickerRole": "date picker",
@@ -58,7 +59,9 @@ return $.widget( "ui.calendar", {
5859
},
5960

6061
refreshRelatedOptions: {
62+
dateFormat: true,
6163
eachDay: true,
64+
locale: true,
6265
max: true,
6366
min: true,
6467
showWeek: true,
@@ -70,7 +73,7 @@ return $.widget( "ui.calendar", {
7073
this.labels = this.options.labels;
7174
this.buttonClickContext = this.element[ 0 ];
7275

73-
this._setLocale( this.options.locale );
76+
this._setLocale( this.options.locale, this.options.dateFormat );
7477

7578
this.date = new $.ui.calendarDate( this.options.value, this._calendarDateOptions );
7679
this.viewDate = this.date.clone();
@@ -177,13 +180,13 @@ return $.widget( "ui.calendar", {
177180
).addClass( "ui-state-focus" );
178181
},
179182

180-
_setLocale: function( locale ) {
183+
_setLocale: function( locale, dateFormat ) {
181184
var globalize = new Globalize( locale ),
182185
weekdayShortFormatter = globalize.dateFormatter({ raw: "EEEEEE" }),
183186
weekdayNarrowFormatter = globalize.dateFormatter({ raw: "EEEEE" });
184187

185-
this._format = globalize.dateFormatter({ date: "short" });
186-
this._parse = globalize.dateParser({ date: "short" });
188+
this._format = globalize.dateFormatter( dateFormat );
189+
this._parse = globalize.dateParser( dateFormat );
187190
this._calendarDateOptions = {
188191
firstDay: globalize.cldr.supplemental.weekData.firstDay(),
189192
formatWeekdayShort: function( date ) {
@@ -590,16 +593,25 @@ return $.widget( "ui.calendar", {
590593

591594
_setOptions: function( options ) {
592595
var that = this,
593-
refresh = false;
596+
refresh = false,
597+
dateAttributes = false;
594598

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

598602
if ( key in that.refreshRelatedOptions ) {
599603
refresh = true;
600604
}
605+
if ( key === "dateFormat" || key === "locale" ) {
606+
dateAttributes = true;
607+
}
601608
} );
602609

610+
if ( dateAttributes ) {
611+
this._setLocale( this.options.locale, this.options.dateFormat );
612+
this.date.setAttributes( this._calendarDateOptions );
613+
this.viewDate.setAttributes( this._calendarDateOptions );
614+
}
603615
if ( refresh ) {
604616
this._refresh();
605617
}
@@ -636,12 +648,6 @@ return $.widget( "ui.calendar", {
636648
if ( key === "eachDay" ) {
637649
this.viewDate.eachDay = value;
638650
}
639-
640-
if ( key === "locale" ) {
641-
this._setLocale( value );
642-
this.date.setAttributes( this._calendarDateOptions );
643-
this.refresh();
644-
}
645651
}
646652
} );
647653

0 commit comments

Comments
 (0)