PDA

View Full Version : Problem with DropTarget in IE not being destroyed when panel removed



tm8747a
5 Sep 2013, 6:34 AM
So I have some code that works fine in Firefox but not in IE. Basically, I have a panel to which columns can be dynamically added. When a column is added, a drop target is added for it so that items from a grid in another part of the page can be dragged into it. It all works fine until you start removing columns and trying to drag, at which point IE throws an error, and I assume it's because the drop target for the column that's been removed is still firing events. I'm including a fiddle where the scenario can be replicated. To cause the error, simply add two columns, remove one, and then try to drag an item from the grid on the right. In IE, you should get a "Unable to get value of the property 'offsetWidth': object is null or undefined" error, while in Firefox it works. To add to the weirdness of it all, if you add an item into the column before removing it, there's no error, the error only occurs if the column was left empty.

http://jsfiddle.net/tm8747a/7hL6G/

ettavolt
6 Sep 2013, 3:13 AM
If you component can be destroyed, you should override destroy method of your component and destroy drop target there.

tm8747a
6 Sep 2013, 6:40 AM
If you component can be destroyed, you should override destroy method of your component and destroy drop target there.

Thanks for the tip, I was able to figure it out. On my render listener where I create the DropTarget, I saved the object created on the column panel, then I added a beforedestroy function to it that first calls destroy on the droptarget assigned to it. Worked like a charm!