I got a little problem, which will be easy to solve for some smart people around here. I have been breaking my head about it for days now.
I used jQuery succesfully to create draggables and droppables. The only problem I can't solve is the following:
How do I make sure that a draggable only can be dragged to a droppable? If it is not dragged inside a droppable it should return to it's starting location.
I use the following code (which works succesfully) to make sure a draggable can only be dragged to a droppable, or else it will jump back to it's starting location.
var question = '#question' + i;
$(question).draggable( {
containment: '#content',
cursor: 'move',
snap: '#content',
revert: 'invalid',
);
The revert: invalid
part does the trick.
However, how do I do this for when it already once has been dragged into a droppable? When I drag a draggable into the droppable, and then drag it outside again it can stay anywhere on the screen (this is because I set the option to false: ui.draggable.draggable( 'option', 'revert', false );
I need the draggable to return to it's starting location again when it is dragged out of the droppable.
Can anyone push me in the right direction? / Any suggestions?
JSFiddle : Click here
Cheers!