Rafael
Rafael

Reputation: 1

how to get/set an acceptance of a dojo.dnd.source

I need to call a function that changes the dnd.source acceptance previously created. Any idea to how to change an existent dojo.dnd.source would be greatful. Code I used to create:

var catalog = new dojo.dnd.Source( 'div_catalog', { accept: ['inStock'] });

sorry for my english, i'm still learning. Thanks again.

Upvotes: 0

Views: 1416

Answers (3)

Rafael
Rafael

Reputation: 1

I found an alternative way to solve the problem, but it is not so good. I simply removed the div that contains the dnd.source and created a new dnd.source with an diferent acceptance. The code I used:

var element = dojo.byId(user_id);<br />
var element_father = element.parentNode;<br />
element_father.removeChild(element);<br />
var div = document.createElement("div");<br />
div.setAttribute('id',element.id);<br />
element_father.appendChild(div);<br />          
var catalog = new dojo.dnd.Source(element.id, {accept: ['outStock']});

I hope that someone knows how to setup an existent dnd.source

Upvotes: 0

Unguis Prime
Unguis Prime

Reputation: 25

I was facing same problem and I found the solution. It's quite easy in fact:

var source = new dojo.dnd.Source("divId", { accept: [] }); // We can use also dojo.dnd.AutoSource

Now created source won't accept anything. To change acceptance we have to add a property to it's accept field like this:

source.accept["acceptType"] = 1;

And same to delete it:

delete source.accept["acceptType"];

I hope it will help someone.

Upvotes: 1

BryanP
BryanP

Reputation: 710

I have played around with this, and I discovered that the "accept" property appears to not be an Array as the dojo manual suggests. It shows as some kind of Object (Other than an Array) in chrome's debugger with an attribute called "text" set to a value of 1 by default. Accessing as element.accept = ""; to disable it works, but after that there is no going back to enabling it again using the same method and trying something like element.accept = ['text']; I also tried accessing it by element.accept.text and this didn't seem to work either once the object was instantiated.

For my application, I needed to allow a single item to be in each td in a table, and I used the following function to do this and preserve the order of the items in the table using a variant of the one listed here. I thought it was worth mentioning.

function changeAccept(source)
{
    var element = document.getElementById(source.node.id);
    console.log("element:"+element);
    var element_father = element.parentNode;
    var td = document.createElement("td");
    td.setAttribute('id',element.id);
    element_father.replaceChild(td,element);

    var newsource = new dojo.dnd.Source(element.id, {accept: ['text']});

    dojo.connect(newsource, "onDrop", function(source, nodes, copy) {
        console.log("Dropped",  newsource, source, nodes, copy);
        newsource.accept = "";
        changeAccept(source);
    });

    return newsource;
}

var priorelement = new dojo.dnd.Source(element.id, {accept: ''}); //disabled
changeAccept(priorelement); //enabled and in same position in table

Upvotes: 2

Related Questions