Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/229153
Change subject: mw.widgets.DateInputWidget: Don't get stuck on today's date if
none given
......................................................................
mw.widgets.DateInputWidget: Don't get stuck on today's date if none given
If no date was given, the calendar would select today, but the
DateInputWidget itself would have no value.
However, this made the date picker ignore attempts to actually choose
today: the calendar already had that date chosen, so no 'change' even
was fired, and date input stayed empty.
Change mw.widgets.CalendarWidget not to actually select today's date,
just focus the calendar on it.
Follow-up to 66686f8c5e4df1c2cc94273918b9328269d2ec09.
Change-Id: I3ba064982b045a577209d56a009ad0098c357754
---
M resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js
1 file changed, 14 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/53/229153/1
diff --git a/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js
b/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js
index 9016e89..7eaa62e 100644
--- a/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js
+++ b/resources/src/mediawiki.widgets/mw.widgets.CalendarWidget.js
@@ -17,8 +17,9 @@
* @constructor
* @param {Object} [config] Configuration options
* @cfg {string} [precision='day'] Date precision to use, 'day' or
'month'
- * @cfg {string|null} [date=null] Day or month date (depending on
`precision`), in the
- * format 'YYYY-MM-DD' or 'YYYY-MM'. When null, defaults to current
date.
+ * @cfg {string|null} [date=null] Day or month date (depending on
`precision`), in the format
+ * 'YYYY-MM-DD' or 'YYYY-MM'. When null, the calendar will show
today's date, but not select
+ * it.
*/
mw.widgets.CalendarWidget = function MWWCalendarWidget( config ) {
// Config initialization
@@ -156,6 +157,7 @@
if (
this.displayLayer === this.previousDisplayLayer &&
+ this.date === this.previousDate &&
this.previousMoment &&
this.previousMoment.isSame( this.moment, this.precision
=== 'month' ? 'month' : 'day' )
) {
@@ -299,6 +301,7 @@
this.previousMoment = moment( this.moment );
this.previousDisplayLayer = this.displayLayer;
+ this.previousDate = this.date;
this.$body.on( 'click', this.onBodyClick.bind( this ) );
};
@@ -396,13 +399,19 @@
* Set the date.
*
* @param {string|null} [date=null] Day or month date, in the format
'YYYY-MM-DD' or 'YYYY-MM'.
- * When null, defaults to current date. When invalid, the date is
not changed.
+ * When null, the calendar will show today's date, but not select
it. When invalid, the date
+ * is not changed.
*/
mw.widgets.CalendarWidget.prototype.setDate = function ( date ) {
var mom = date !== null ? moment( date, this.getDateFormat() )
: moment();
if ( mom.isValid() ) {
this.moment = mom;
- this.setDateFromMoment();
+ if ( date !== null ) {
+ this.setDateFromMoment();
+ } else if ( this.date !== null ) {
+ this.date = null;
+ this.emit( 'change', this.date );
+ }
this.displayLayer = this.getDisplayLayers()[ 0 ];
this.updateUI();
}
@@ -436,7 +445,7 @@
* Get current date, in the format 'YYYY-MM-DD' or 'YYYY-MM', depending
on precision. Digits will
* not be localised.
*
- * @returns {string} Date string
+ * @returns {string|null} Date string
*/
mw.widgets.CalendarWidget.prototype.getDate = function () {
return this.date;
--
To view, visit https://gerrit.wikimedia.org/r/229153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ba064982b045a577209d56a009ad0098c357754
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits