From ae76e8cfe427b03676428ff8a004eeeb72822a89 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 11 Feb 2019 13:52:39 +0000 Subject: [PATCH] mw.widgets: Make TitleSearchWidget read-only-able Change-Id: I3eed52438c1e416d4dcdedb564bb9df3745d0f77 --- .../mw.widgets.TitleSearchWidget.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js index b9bd1e00a9..f1f98a2760 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js @@ -77,6 +77,11 @@ var widget = this; this.getRequestData().done( function ( data ) { + if ( widget.query.isReadOnly() ) { + // The request object is always abortable, so just + // prevent the results from displaying + return; + } // Parent method mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget ); widget.results.addItems( widget.getOptionsFromData( data ) ); @@ -102,4 +107,29 @@ return response.query || {}; }; + /** + * Check if the widget is read-only. + * + * @return {boolean} + */ + mw.widgets.TitleSearchWidget.prototype.isReadOnly = function () { + return this.query.isReadOnly(); + }; + + /** + * Set the read-only state of the widget. + * + * @param {boolean} readOnly Make input read-only + * @chainable + * @return {mw.widgets.TitleSearchWidget} The widget, for chaining + */ + mw.widgets.TitleSearchWidget.prototype.setReadOnly = function ( readOnly ) { + this.query.setReadOnly( readOnly ); + if ( readOnly ) { + // Hide results + this.results.clearItems(); + } + return this; + }; + }() ); -- 2.20.1