Login Register

add dnd to existing list programatically

I'm feeling really dumb here and I'm hoping someone can help. I have en existing list:

<ul id='myid'>
<li id='firstitem'>First Item</li>
<li id='seconditem'>Second Item</li>
</ul>

I would like to add dnd to this list, however I have no control over the original markup so I need to do it programitically.
I have tried all kinds of dojo.dnd.Source('myid') permutations and read the tests and Book, but I just think I don't understand something important.
Is there an easy was to create a dnd source/target from an existing list or is the only way to read the elements in from the list, destroy the original list, and then create a new dnd Source and add each item in.

Thanks in advance,
Jon

It is easy: Examine test

It is easy:

  • Examine test files in dojo/tests/dnd directory: test_container.htnl, test_selector.html, and test_dnd.html to see how you can instantiate DnD objects programmatically on different HTML elements.
  • Add "dojoDndItem" class to all <li> items, so they will be picked up by DnD automatically.
  • Create a DnD source container on your "myid" node. You may want to use optional parameters described in the documentation.
  • Done.