Skip to content

Commit 6f9d266

Browse files
committed
Datepicker: Fix min / max attribute and add proper option parsing
1 parent 9428256 commit 6f9d266

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

ui/widgets/datepicker.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ var widget = $.widget( "ui.datepicker", {
6161

6262
_create: function() {
6363
this.suppressExpandOnFocus = false;
64+
this._parse = new Globalize( this.options.locale ).dateParser( this.options.dateFormat );
6465

6566
if ( $.type( this.options.max ) === "string" ) {
66-
this.options.max = Globalize.parseDate( this.options.max, { raw: "yyyy-MM-dd" } );
67+
this.options.max = this._parse( this.options.max );
6768
}
6869
if ( $.type( this.options.min ) === "string" ) {
69-
this.options.min = Globalize.parseDate( this.options.min, { raw: "yyyy-MM-dd" } );
70+
this.options.min = this._parse( this.options.min );
7071
}
7172

7273
this._createCalendar();
@@ -79,30 +80,30 @@ var widget = $.widget( "ui.datepicker", {
7980
_getCreateOptions: function() {
8081
var max = this.element.attr( "max" ),
8182
min = this.element.attr( "min" ),
83+
parser = new Globalize( "en" ).dateParser( { raw: "yyyy-MM-dd" } ),
8284
options = {};
8385

8486
if ( max !== undefined ) {
85-
options.max = Globalize.parseDate( max, { raw: "yyyy-MM-dd" } );
87+
options.max = parser( max );
8688
}
8789

8890
if ( min !== undefined ) {
89-
options.min = Globalize.parseDate( min, { raw: "yyyy-MM-dd" } );
91+
options.min = parser( min );
9092
}
9193

9294
return options;
9395
},
9496

9597
_createCalendar: function() {
96-
var that = this,
97-
globalize = new Globalize( this.options.locale );
98+
var that = this;
9899

99100
this.calendar = $( "<div>" ).appendTo( this._appendTo() );
100101
this._addClass( this.calendar, "ui-datepicker", "ui-front" );
101102

102103
// Initialize calendar widget
103104
this.calendarInstance = this.calendar
104105
.calendar( $.extend( {}, this.options, {
105-
value: globalize.dateParser( this.options.dateFormat )( this.element.val() ),
106+
value: this._parse( this.element.val() ),
106107
select: function( event ) {
107108
that.element.val( that.calendarInstance.value() );
108109
that.close();
@@ -118,7 +119,6 @@ var widget = $.widget( "ui.datepicker", {
118119
this.calendarInstance.buttonClickContext = that.element[ 0 ];
119120

120121
this._setHiddenPicker();
121-
122122
this.element.attr( {
123123
"aria-haspopup": true,
124124
"aria-owns": this.calendar.attr( "id" )
@@ -302,7 +302,7 @@ var widget = $.widget( "ui.datepicker", {
302302

303303
value: function( value ) {
304304
if ( arguments.length ) {
305-
this.valueAsDate( this.calendarInstance._parse( value ) );
305+
this.valueAsDate( this._parse( value ) );
306306
} else {
307307
return this._getParsedValue() ? this.element.val() : null;
308308
}
@@ -334,10 +334,16 @@ var widget = $.widget( "ui.datepicker", {
334334
},
335335

336336
_getParsedValue: function() {
337-
return this.calendarInstance._parse( this.element.val() );
337+
return this._parse( this.element.val() );
338338
},
339339

340340
_setOption: function( key, value ) {
341+
if ( key === "max" || key === "min" ) {
342+
if ( typeof value === "string" ) {
343+
value = this._parse( value );
344+
}
345+
}
346+
341347
this._super( key, value );
342348

343349
if ( $.inArray( key, this.calendarOptions ) !== -1 ) {

0 commit comments

Comments
 (0)