Login Register

Dnd Item doesn't added properly

Hello!

I create a dnd Source with the following method:

function init() {
dojo.subscribe("/dnd/drop", function(source, nodes, copy, target){
loadRemotely(source, nodes, target);
});

var qTypesSource = new dojo.dnd.Source("questiontypes", {horizontal: true, copyOnly: true, accept: ["none"], skipForm: true});
qTypesSource.checkAcceptance = function(source, nodes){ false};

contentSource = new dojo.dnd.Source("content", {horizontal: true, copyOnly: false, accept: ["question", "template"], skipForm: true});

}

dojo.addOnLoad(init);

qTypesSource is actually a Pure Source, not a Target. It contains several draggable elements like this:

<div class="dojoDndItem" dndType="question" id="q1" name="multipledecision">
<div class="question">multiple decision</div>
</div>

The idea is that i can drop these elements into contentSource, i make an xhrpost with the info, and a server side velocity macro generates the html representation of the element, wich also contains some server side data.

The js function that does this is:

function loadRemotely(source, nodes, target) {
var sourceId = nodes[0].id;
var sourceName = nodes[0].getAttribute("name");
var targetId = target.current.id;
if(sourceId != targetId) {
saveCurrentValue();
xhrPostUrlParamsCallback("addNewQuestion.htm", [{name:"sourceId", value:sourceId}, {name:"targetId", value:targetId}, {name:"rfxId", value:$rfx.id},{name:"questiontype", value:sourceName}, {name:"before",value:target.before}], function(response) {
dojo.byId("content").innerHTML = response;
});
}
}

My problem is that if i drop a new question into the qTypesSource Source, the item doesn't added proberly to the Source.
It is visualy there, but when i start to drag it i get "source.getItem(nodes[i].id) has no properties" message.

update: if i refresh the

update: if i refresh the whole page, it is OK. It seems innerHTML is not enough, to update the Source with the new content.

No it's not. You have to use

No it's not. You have to use a creator function, or resort to a low-level hackery. Please search the archive of this forum for multiple discussions of that.

Hi Eugene! I have a problem

Hi Eugene!

I have a problem with node creator, wich i don't really understand.

I rewritten the loadremotely function like this:

function loadRemotely(source, nodes, target) {
var sourceId = nodes[0].id;
var sourceName = nodes[0].getAttribute("name");
var targetId = target.current.id;
if(sourceId != targetId) {
saveCurrentValue();
xhrPostUrlParamsCallback("addNewQuestion.htm", [{name:"sourceId", value:sourceId}, {name:"targetId", value:targetId}, {name:"rfxId", value:$rfx.id},{name:"questiontype", value:sourceName}, {name:"before",value:target.before}], function(response) {
dojo.byId("content").innerHTML = response;
contentSource.clearItems();
var questionNodes = new Array();
var childNodes = dojo.byId("content").childNodes;
for(var i = 0 , j = 0; i < childNodes.length; i++) {
if(childNodes[i].tagName == "DIV") {
questionNodes[j] = childNodes[i];
j++;
}
}
contentSource.insertNodes(false, questionNodes);
});
}
}

And i also rewritten my contentSource like this:

var node_creator = function(data, hint) {
return {node: node, data: data, type: ["text"]};
};

contentSource = new dojo.dnd.Source("content", {creator: node_creator, horizontal: true, copyOnly: false, accept: ["question", "template"], skipForm: true});

The problem is that the node_creator is called when i drag a question to contentSource. It is not good, because i don't want to add these questions to contentSource, just the server side divs, that come from my velocity templates. So a want node creator to be called only in my explicit insertNodes function.

It is hard to read

It is hard to read unformatted code. Send an e-mail to me (eugene at this domain) and attach relevant pieces.

You can read more about the

You can read more about the creator function here: http://docs.google.com/Doc?id=d764479_11fcs7s397.

Are there more docs like

Are there more docs like this one that are available for reference? This is exactly what I am looking for to be able to better understand dojo and its api.

I have a similar (but

I have a similar (but complete) technical doc for dojox.gfx. Charting technical docs are planned but not there yet. I don't know the situation with other Dojo sub-projects. Personally I think that user's documentation in the Dojo Book is good, but we need to provide a developer's documentation as well — majority of our users are seasoned developers who need to understand underlying technical ideas, design decisions, and involved trade-offs. That's why I'm set on writing technical docs for all projects I support directly. I hope other owners and developer will follow my lead.

And again I have to stress that the best way to understand various pieces of Dojo is to look at the code of tests and demos. If it doesn't help — "Use the Source, Luke!", which is in most cases are very good written — that's what I do when I have questions about Dojo libraries. But of course it doesn't replace completely the real technical documentation.

sorry, this is the formatted

sorry, this is the formatted version of the method:
(i couldn't do it fully, but i hope it is readable.)

function loadRemotely(source, nodes, target) {
              var sourceId = nodes[0].id;
              var sourceName = nodes[0].getAttribute("name");
              var targetId = target.current.id;
              if(sourceId != targetId) {
            xhrPostUrlParamsCallback("addNewQuestion.htm", [{name:"sourceId", value:sourceId}, {name:"targetId", value:targetId}, {name:"rfxId", value:$rfx.id},{name:"questiontype", value:sourceName}, {name:"before",value:target.before}], function(response) {
            dojo.byId("content").innerHTML = response;
            contentSource.clearItems();
            var questionNodes = new Array();
            var childNodes = dojo.byId("content").childNodes;
            for(var i = 0 , j = 0; i < childNodes.length; i++) {
                if(childNodes[i].tagName == "DIV") {
              questionNodes[j] = childNodes[i];
              j++;
                }
            }
                    contentSource.insertNodes(false, questionNodes);
                    });
              }
        }

Look at this post and you

Look at this post and you find the solution for your problem ;) You must overwrite the Avatar.js.
http://www.dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/dr...