dart-html5-dnd icon indicating copy to clipboard operation
dart-html5-dnd copied to clipboard

Associating data with a drag

Open danschultz opened this issue 11 years ago • 3 comments

You can't associate any data to a drag. It'd be convenient to do:

var dragGroup = new DraggableGroup();

var person = new Person()
    ..name = 'David Gilmour';
dragGroup.install(personDiv, data: person);

var dropGroup = new DroppableGroup();
dropGroup.onDrop.listen((DropzoneEvent event) => print(event.data.name));
dropGroup.accept.add(dragGroup);

Supporting this with installAll() is a bit trickier.

danschultz avatar Jul 02 '13 20:07 danschultz

I think you'd better associate such data outside of the drag and drop. You could, for example, keep a map with the element's id and the associated Person. Then, when a drag occurred, you can look up the id of the dragged element.

marcojakob avatar Jul 02 '13 20:07 marcojakob

This a common paradigm with Drag and Drop APIs. Off the top of my head, Java Swing, Flex, and HTML5 support behavior like this.

danschultz avatar Jul 02 '13 21:07 danschultz

Yes, HTML5 does support this, but then you would need to serialize your data (I assumed from your example with person that you didn't mean to serialize Person).

In HTML5, the benefit of adding data to a drag operation is that another application could do something with the associated data (like dragging an image to the desktop). As this is not supported in IE9 I chose not to implement it.

Currently, I don't see a big benefit of adding this to the library. If you think otherwise, could you add more details about your use case?

marcojakob avatar Jul 02 '13 21:07 marcojakob