Here is my solution, it allows you to drag and clone a clone, and then replace it as needed with another drag and drop. It also has a callback function parameter that passes the dumped div object back so you can do something with the selected jquery div after it is deleted.
refreshDragDrop = function(dragClassName,dropDivId, callback) { $( "." + dragClassName ).draggable({ connectToSortable: "#" + dropDivId, helper: "clone", revert: "invalid" }); $("#" + dropDivId).droppable({ accept: '.' + dragClassName, drop: function (event, ui) { var $this = $(this), maxItemsCount = 1; if ($this.children('div').length == maxItemsCount ){ //too many item,just replace $(this).html($(ui.draggable).clone()); //ui.sender.draggable('cancel'); } else { $(this).append($(ui.draggable).clone()); } if (typeof callback == "function") callback($this.children('div')); } }); }
Damon Hogan Jan 28 '16 at 22:35 2016-01-28 22:35
source share