Login Register

doing DnD with widgets

Hi All,
I have in my application a container widget which within it nesting widgets are created on run time (i.e., I can't define them in the template). I'd like to allow DnD of these nesting widgets, so I did the following:
1) in the startup function of the container widget I defined a creator function and created the target node like this:
this.dndRoot = new dojo.dnd.Source(this.containerNode, {accept: ["myElementsKey"], creator:dndNodeCreator});
(the containerNode is actually a tbody element)
2) when the user wants to add a widget to the container, eventually there is the call:

this.dndRoot.insertNodes(false,
[{myParams1: params1, myParams2: params2},false);
(the created widgets root element is tr)
During debugging I see that the node is inserted properly to the map object (which is defined in dojo.dnd.Container), but when I try to drag the nested widget, I see that this map is empty, and the code fails when the DnD manager tries to create an Avatar (in dojo.dnd.Avatar, line 39, the code : source.getItem(this.manager.nodes[i].id) returns undefined).
Does anyone has any idea how to tackle this problem?

thanks
Yoav

Probably something wrong

Probably something wrong with the creator function. I do DnD with widgets in my programs without any problems.

Here's my creator function

var dndNodeCreator = function(data, hint)
{
var myWidget= new MyWidget({name:data.params1, description:data.params2});
return {node: myWidget.domNode, data: data, type: ['myElementsKey']};
};

I just changed the names of the variables and widget type, but basically that's my creator function.

Can you post your creator function? I can't figure out what am I doing wrong here

Thanks
Yoav

Try to wrap your widget in

Try to wrap your widget in <div>:

var dndNodeCreator = function(data, hint){
    var myWidget= new MyWidget({name:data.params1, description:data.params2}),
        div = dojo.doc.createElement("div");
    div.appendChild(myWidget.domNode);
    return {node: div, data: data, type: ['myElementsKey']};
};

It worked

thanks for the tip, it worked