PDA

View Full Version : Problem with removing a component that is Ext.dd.DropTarget



countdown
28 Jun 2010, 2:39 AM
Hi
In my application I have many components where I create an Ext.dd.DropTarget on their elements!
Some components may be later removed (e.g. a tab window closed). I have noticed that in the Ext.dd.DragDropMgr the 'ids' array which contains all elements in a ddGroup those components aren't removed!!!
The grid and tree with automatic DD are removed but not manually added components!

What would be the best way of emptying the Ext.dd.DragDopMgr ids array ? Is this a bug and should Ext manually handle this or am I maybe using the DropTarget wrong?

I hope it is understandable what the issue is, if not any questions are welcome!
thanks for help!

Animal
28 Jun 2010, 2:41 AM
It's a bug in your code.

If you create an Ext.dd.DropTarget, then you are responsible for destroying it when no longer needed.

countdown
28 Jun 2010, 3:23 AM
thanks Animal! was affraid this was the issue!
dropTarget.destroy() on beforeDestroy component does the trick!
Only question remains how to automate this process, since there is no point in keeping a dropTarget if the target is gone...or is it? :)

Animal
28 Jun 2010, 3:39 AM
Right. Didn't you say you had the solution? A beforedestroy listener on the Component?

countdown
28 Jun 2010, 4:01 AM
yes, but I manually added a listener to the component.
I was thinking more in the lines of overriding dropTarget constructor and adding there a before destroy listener to the linked component (have to figure out how to override constructors though :D ). But that would probably mess up some extended classes like TreeDropZone, so I'll probably drop that idea!
Thanks again for help.

Animal
28 Jun 2010, 4:04 AM
Override a constructor === a subclass.

But the DropTarget has no idea whether the Element that it is operating on is part of a Component.

You have it upside down. The Component's initialization must take care of setting things up so that it tears itself down correctly.

You might need overrides, or a subclass on the Component class.

Juanito
30 Oct 2012, 9:20 AM
Beware that the beforedestroy event and the beforeDestroy event do not guarantee that the component is going to get destroyed. If any of the listeners return false, the destroy process is stopped and you will have a half destroyed component, in your case, your drag and drop won't work.

It's not very common to stop the destroy process, but it's still possible.

The way I handle it is by overriding the destroy method, at that point, you're guaranteed that the component will be destroyed. You should do your destruction and the call the parent destroy method.