Reputation: 2265
I'm trying to use Dojo dnd Source(1.4.2) to create an interface where I can move some objects from a Source to a Target. It is working fine, but I want to change the behaviour in order to execute a check before actually doing the D&D, so if the check fails, an error message is shown to the user, and the D&D is not made. I've tried the following example I found in a blog:
dojo.subscribe("/dnd/drop", function(source,nodes,iscopy)
{
if (nodes[0].id == 'docs_menu'){
dojo.publish("/dnd/cancel");
dojo.dnd.manager().stopDrag();
alert("Drop is not permitted");
}
}
);
But it fails saying that this.avatar is null. Does anybody know how to do this?
Thanks.
Jose
Upvotes: 1
Views: 2716
Reputation: 407
I encountered a case in which I had limitations on the order of items inside the list. Some items had to precede others. The check could not be done in the checkAcceptance stage due to the fact that the order is not set at that stage. I solved this the following way.
on(mySource, "Drop", function(source, nodes, copy){
var invalid = false;
// ... run the checks to see if the new order is valid
// Keep the original order in a parameter named *data*
if(invalid == true) {
mySource.selectAll();
mySource.deleteSelectedNodes();
mySource.insertNodes(false, data);
}
else
{
// Have the data added
}
});
Upvotes: 0
Reputation: 3395
The correct way to do this kind of check is to override checkAcceptance(source, nodes)
function in dojo.dnd.Source
.
var target = dojo.dnd.Source(node, {
checkAcceptance(source, nodes) : function() {
if (nodes[0].id == 'docs_menu') {
return false;
}
return this.inhertied(arguments);
}
});
Refer to the doc for more details.
Upvotes: 1