From: Bartosz DziewoƄski Date: Fri, 29 Jun 2018 22:49:08 +0000 (+0200) Subject: mw.widgets.TitleWidget: Don't mark optional fields as invalid when empty X-Git-Tag: 1.34.0-rc.0~4885^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles_versions%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=97c2b68a17a54a1cc0ed6d8e49e7d33e4543115c;p=lhc%2Fweb%2Fwiklou.git mw.widgets.TitleWidget: Don't mark optional fields as invalid when empty Bug: T198402 Change-Id: I0e69f2015894ddf5ad53190740255f1c073fd76a --- diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js index 2bbeabf56e..2340f9cfe5 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js @@ -26,8 +26,8 @@ * @cfg {boolean} [showMissing=true] Show missing pages * @cfg {boolean} [addQueryInput=true] Add exact user's input query to results * @cfg {boolean} [excludeCurrentPage] Exclude the current page from suggestions - * @cfg {boolean} [validateTitle=true] Whether the input must be a valid title (if set to true, - * the widget will marks itself red for invalid inputs, including an empty query). + * @cfg {boolean} [validateTitle=true] Whether the input must be a valid title + * @cfg {boolean} [required=false] Whether the input must not be empty * @cfg {Object} [cache] Result cache which implements a 'set' method, taking keyed values as an argument * @cfg {mw.Api} [api] API object to use, creates a default mw.Api instance if not specified */ @@ -369,7 +369,13 @@ * @return {boolean} The query is valid */ mw.widgets.TitleWidget.prototype.isQueryValid = function () { - return this.validateTitle ? !!this.getMWTitle() : true; + if ( !this.validateTitle ) { + return true; + } + if ( !this.required && this.getQueryValue() === '' ) { + return true; + } + return !!this.getMWTitle(); }; }( jQuery, mediaWiki ) );