Opened 10 years ago

Last modified 5 years ago

#15585 new defect

Dojo dnd selfAccept

Reported by: Saurabh Gupta Owned by: Eugene Lazutkin
Priority: undecided Milestone: 1.15
Component: DnD Version: 1.7.3
Keywords: Cc:
Blocked By: Blocking:



I've been spending some time with the dojo drag & drop section(its mind blowing stuff!). I was following this tutorial :

Before I get into the bug I faced, I'd like to quote :

"Avoiding Duplicate Items One thing I hadn’t pointed out before was that in version 3 of our demo, in addition to specifying the node creator function when instantiating our Source objects, we also passed a parameter copyOnly: true. This overrides the default drag semantics and performs a copy operation by default instead of a move. This is nice because it means we can avoid removing items from the catalog(s) when we drag them around. The downside is that if you copy an item on the container where it already lives, it duplicates the item.

Logically, this shouldn’t happen because we’re not specifying the accept type on the catalogs, so they should default to "text" and keep us from dropping the products on them (we’re explicitly giving them different types, remember). If you dig into the Dojo source, however, you’ll see that the function that checks for matches between item types and container accept values automatically accepts “self drops”, short circuiting the item type check. Often, that’s the correct behavior, but for our copyOnly–style DnD here, this is backwards. Fortunately again, overriding this is easy: just set the selfAccept property to false."

So, having set the selfAccept to false(& copyOnly to true) on my target, I found that it still creates duplicate items! I was able to reproduce this behavior on the 4th step of the tutorial as well - I set selfAccept to false & it still created duplicate items on the cart.

As far as I can tell, this boils down to the checkAcceptance method of the target(inherited from dojo.dnd.Source). In that method, I don't think its checking for duplicate items :

	checkAcceptance: function(source, nodes){
		if(this == source){
			return !this.copyOnly || this.selfAccept;
		for(var i = 0; i < nodes.length; ++i){
			var type = source.getItem(nodes[i].id).type;
			// type instanceof Array
			var flag = false;
			for(var j = 0; j < type.length; ++j){
				if(type[j] in this.accept){
					flag = true;
				return false;	// Boolean
		return true;	// Boolean

Just to re-confirm, my understanding is that when I set selfAccept to false on my target(dojo.dnd.Target), it should no longer accept items that it already has?


Change History (2)

comment:1 Changed 6 years ago by dylan

Milestone: tbd1.12

Will look into this for 1.12.

comment:2 Changed 5 years ago by dylan

Milestone: 1.131.15

Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.

Note: See TracTickets for help on using tickets.