RC Filters: Check if app is initialized before calling change tags
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterTagMultiselectWidget.js
index d59fdfb..c7db7c6 100644 (file)
         * @inheritdoc
         */
        mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onChangeTags = function () {
-               // Parent method
-               mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onChangeTags.call( this );
+               // If initialized, call parent method.
+               if ( this.controller.isInitialized() ) {
+                       mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onChangeTags.call( this );
+               }
 
                this.emptyFilterMessage.toggle( this.isEmpty() );
        };
                        ) {
                                this.addTag( item.getName(), item.getLabel() );
                        } else {
-                               this.removeTagByData( item.getName() );
+                               // Only attempt to remove the tag if we can find an item for it (T198140, T198231)
+                               if ( this.findItemFromData( item.getName() ) !== null ) {
+                                       this.removeTagByData( item.getName() );
+                               }
                        }
                }
 
                        // Remove capsule widgets if they're not selected
                        highlightedItems.forEach( function ( filterItem ) {
                                if ( !filterItem.isSelected() ) {
-                                       this.removeTagByData( filterItem.getName() );
+                                       // Only attempt to remove the tag if we can find an item for it (T198140, T198231)
+                                       if ( this.findItemFromData( filterItem.getName() ) !== null ) {
+                                               this.removeTagByData( filterItem.getName() );
+                                       }
                                }
                        }.bind( this ) );
                }