Taking the full javascript code from the link you gave, you can change it as follows to make it work:
$(function() {
$(".elementbar div").draggable({
connectToSortable: '.column',
cursor: 'move',
cursorAt: { top: 0, left: 0 },
helper: 'clone',
revert: 'invalid'
});
$(".elementbar div, .elementbar div img").disableSelection();
$(".column").sortable({
connectWith: '.column',
cursor: 'move',
cursorAt: { top: 0, left: 0 },
placeholder: 'ui-sortable-placeholder',
tolerance: 'pointer',
stop: function(event, ui) {
if (ui.item.hasClass("elemtxt")) {
ui.item.replaceWith('<div class="element element-txt">This text box has been added!</div>');
}
}
});
$(".element").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all");
});
There were a couple of issues:
- The drop event (that you show in your question) wasn't firing because you weren't
accept
ing the right content.
- If you have both
.sortable
& .droppable
you end up with weird double events firing. This is unnecessary anyway, since you can effectively grab the drop event from sortable's events given that you've linked it with the draggable.
One other thing to note - it would have been nicer to use the sortable's receive
event instead of stop
(since stop gets fired every time any sorting stops & receive is specifically there to fire when you drop a new item into the sort list), but it doesn't work properly because the item
hasn't yet been added to the sortable list, so you aren't able to change it at that point. It works ok on stop simply because none of the other sortable items have the elemtxt
class.