UiItemList was only partially destructed
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jan 2017 17:07:57 +0000 (18:07 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jan 2017 17:07:57 +0000 (18:07 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList.js

index 5a7c0811ae22200a7a70b21b62f526ac61ae4a7b..53b5f902014b8a8a7c0b26ceb49244949e7f85fc 100644 (file)
@@ -6,7 +6,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLabSuite/Core/Ui/ItemList
  */
-define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'WoltLabSuite/Core/Ui/Suggestion'], function(Core, Dictionary, Language, DomTraverse, EventKey, UiSuggestion) {
+define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'WoltLabSuite/Core/Ui/Suggestion', 'Ui/SimpleDropdown'], function(Core, Dictionary, Language, DomTraverse, EventKey, UiSuggestion, UiSimpleDropdown) {
        "use strict";
        
        var _activeId = '';
@@ -38,6 +38,23 @@ define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'WoltLabSu
                                throw new Error("Expected a valid element id, '" + elementId + "' is invalid.");
                        }
                        
+                       // remove data from previous instance
+                       if (_data.has(elementId)) {
+                               var tmp = _data.get(elementId);
+                               
+                               for (var key in tmp) {
+                                       if (tmp.hasOwnProperty(key)) {
+                                               var el = tmp[key];
+                                               if (el instanceof Element && el.parentNode) {
+                                                       elRemove(el);
+                                               }
+                                       }
+                               }
+                               
+                               UiSimpleDropdown.destroy(elementId);
+                               _data.delete(elementId);
+                       }
+                       
                        options = Core.extend({
                                // search parameters for suggestions
                                ajax: {