views:

153

answers:

1

Hi, 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

+1  A: 

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.

Alex Cheng