mw.widgets.CategorySelector: Prevent duplicates
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 22 Dec 2015 17:19:00 +0000 (18:19 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 22 Dec 2015 17:21:50 +0000 (18:21 +0100)
CapsuleMultiSelectWidget should take care of it by itself, but its
logic is foiled by how we canonicalize the data.

Bug: T122219
Change-Id: I2bdc3681dfde3080067ea12e5a036824d154a72f

resources/src/mediawiki.widgets/mw.widgets.CategorySelector.js

index 59f1d50..1e65da5 100644 (file)
                } );
        };
 
+       /**
+        * @inheritdoc
+        */
+       CSP.getItemFromData = function ( data ) {
+               // This is a bit of a hack... We have to canonicalize the data in the same way that
+               // #createItemWidget and CategoryCapsuleItemWidget will do, otherwise we won't find duplicates.
+               data = mw.Title.newFromText( data, NS_CATEGORY ).getMainText();
+               return OO.ui.mixin.GroupElement.prototype.getItemFromData.call( this, data );
+       };
+
        /**
         * Validates the values in `this.searchType`.
         *