...

View Full Version : jQuery Adding and removing between connected lists



metazai
11-12-2009, 01:20 PM
Greetings! I'm somewhat of a jquery noob, so please be kind . . .

I have a page where a user can drag options into a box and order them as they see fit. It's NDA for a client, unfortunately, but it's more or less built exactly on the brilliantly simple code stickman posted at: http://the-stickman.com/files/jquery/draggable-sortable.html

Which is great, but what if I want the user to be able to REMOVE an item from the box, just drag it out into the ether and have it disappear? It can still be dragged in from the initial lists, of course, but to remove it from the box with the same "dragging" interface seems natural -- only I can't see how to do it. Any ideas?

Fumigator
11-12-2009, 04:34 PM
I haven't done much with drag/drop (just a little experimentation) but it seems to me you can assign the outer div as a droppable object with a callback function that removes the object being dropped on it. Worth a shot...

metazai
11-13-2009, 08:49 PM
I wrapped one of the original "drag from" lists in a droppable div id, and added this to the bottom.



jQuery('#droppable').droppable({
drop: function() {
$(this).parent().remove();
return false;
}

As you may have guessed, it doesn't work. It removes the #droppable div.

I've tried some variations, but they just break it further. Suggestions?

Fumigator
11-13-2009, 10:59 PM
What if you created a little div with a graphic of a trash can on it and made that droppable? Then you can just remove anything that's dropped on it.

metazai
11-14-2009, 01:32 AM
No, I'm afraid that's still not working. Am I using the

$(this).parent().remove();
correctly?

Fumigator
11-14-2009, 05:44 AM
I dunno, is it selecting the correct element? If in doubt, you can always stick an id on the element and select it directly using the id.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum