Catrope has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/357963 )

Change subject: UsersMultiSelectWidget: Port from CapsuleMultiselectWidget to 
MenuTagMultiselectWidget
......................................................................

UsersMultiSelectWidget: Port from CapsuleMultiselectWidget to 
MenuTagMultiselectWidget

Bonus:
* Remove puzzling code that claimed to fix a bug that I couldn't reproduce
  but instead made single-character searches never display suggestions
* Clear the input after choosing a menu item

Change-Id: I44e72205880d152639ee823238dc5ab84d34402b
---
M includes/widget/UsersMultiselectWidget.php
M resources/src/mediawiki.widgets/mw.widgets.UsersMultiselectWidget.js
2 files changed, 21 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/357963/1

diff --git a/includes/widget/UsersMultiselectWidget.php 
b/includes/widget/UsersMultiselectWidget.php
index d24ab7b..999cb6a 100644
--- a/includes/widget/UsersMultiselectWidget.php
+++ b/includes/widget/UsersMultiselectWidget.php
@@ -53,7 +53,7 @@
 
        public function getConfig( &$config ) {
                if ( $this->usersArray !== null ) {
-                       $config['data'] = $this->usersArray;
+                       $config['selected'] = $this->usersArray;
                }
                if ( $this->inputName !== null ) {
                        $config['name'] = $this->inputName;
diff --git 
a/resources/src/mediawiki.widgets/mw.widgets.UsersMultiselectWidget.js 
b/resources/src/mediawiki.widgets/mw.widgets.UsersMultiselectWidget.js
index d7464b9..c1676b8 100644
--- a/resources/src/mediawiki.widgets/mw.widgets.UsersMultiselectWidget.js
+++ b/resources/src/mediawiki.widgets/mw.widgets.UsersMultiselectWidget.js
@@ -14,7 +14,7 @@
         * newline-separated usernames.
         *
         * @class
-        * @extends OO.ui.CapsuleMultiselectWidget
+        * @extends OO.ui.MenuTagMultiselectWidget
         *
         * @constructor
         * @param {Object} [config] Configuration options
@@ -57,16 +57,12 @@
 
                // Events
                // Update contents of autocomplete menu as user types letters
-               this.$input.on( {
+               this.input.$input.on( {
                        keyup: this.updateMenuItems.bind( this )
-               } );
-               // When option is selected from autocomplete menu, update the 
menu
-               this.menu.connect( this, {
-                       select: 'updateMenuItems'
                } );
                // When list of selected usernames changes, update hidden input
                this.connect( this, {
-                       change: 'updateHiddenInput'
+                       change: 'onMultiselectChange'
                } );
 
                // API init
@@ -75,7 +71,7 @@
 
        /* Setup */
 
-       OO.inheritClass( mw.widgets.UsersMultiselectWidget, 
OO.ui.CapsuleMultiselectWidget );
+       OO.inheritClass( mw.widgets.UsersMultiselectWidget, 
OO.ui.MenuTagMultiselectWidget );
        OO.mixinClass( mw.widgets.UsersMultiselectWidget, 
OO.ui.mixin.PendingElement );
 
        /* Methods */
@@ -83,10 +79,10 @@
        /**
         * Get currently selected usernames
         *
-        * @return {Array} usernames
+        * @return {string[]} usernames
         */
        mw.widgets.UsersMultiselectWidget.prototype.getSelectedUsernames = 
function () {
-               return this.getItemsData();
+               return this.getValue();
        };
 
        /**
@@ -95,7 +91,7 @@
         * @private
         */
        mw.widgets.UsersMultiselectWidget.prototype.updateMenuItems = function 
() {
-               var inputValue = this.$input.val();
+               var inputValue = this.input.getValue();
 
                if ( inputValue === this.inputValue ) {
                        // Do not restart api query if nothing has changed in 
the input
@@ -134,12 +130,9 @@
 
                                // Remove all items from menu add fill it with 
new
                                this.menu.clearItems();
-
-                               // Additional check to prevent bug of 
autoinserting first suggestion
-                               // while removing user from the list
-                               if ( inputValue.length > 1 || 
suggestions.length > 1 ) {
-                                       this.menu.addItems( suggestions );
-                               }
+                               this.menu.addItems( suggestions );
+                               // Make the menu visible; it might not be if it 
was previously empty
+                               this.menu.toggle( true );
 
                                this.popPending();
                        }.bind( this ) ).fail( this.popPending.bind( this ) );
@@ -160,4 +153,14 @@
                }
        };
 
+       /**
+        * React to the 'change' event.
+        *
+        * Updates the hidden input and clears the text from the text box.
+        */
+       mw.widgets.UsersMultiselectWidget.prototype.onMultiselectChange = 
function () {
+               this.updateHiddenInput();
+               this.input.setValue( '' );
+       };
+
 }( jQuery, mediaWiki ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/357963
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I44e72205880d152639ee823238dc5ab84d34402b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to