agis
agis

Reputation: 1841

jQuery UI sortable - do something when user starts dragging an element from a specific block

This question is related to this

I have two block one is "draggable" and the other is "sortable".

What I want to do is when I start dragging an item from "sortable" to do something via jQuery.

this is my JS:

 $(".sortableList").sortable({
 start: function(event, ui) {
       alert("Do something here!");
    }
 });
 $(".draggable").draggable({
 connectToSortable: '.sortableList',
 cursor: 'pointer',
 helper: 'clone',
 revert: 'invalid',
 start: function (event, ui) {
     $(this).addClass('testing');
 }
 });

 $("#sidebar-wrapper").droppable({
 accept: 'li',
 drop: function (event, ui) {
     ui.helper.remove();
 }
 });

The problem is that is doing something before I drop the element from "draggable" to "sortableList" and I want to do something when element is dragged from "sortableList."

Here's a jsbin.

Any suggestions on how can I do this?

Upvotes: 2

Views: 726

Answers (1)

James Thorpe
James Thorpe

Reputation: 32202

I'm not sure if this would count as a bug in the jQuery UI Sortable or not - it certainly seems that it might be. One way you can get around it is to query the event parameter in start:

$(".sortableList").sortable({
    start: function(event, ui) {
        if (event.handleObj.namespace=="sortable")
            alert("Do something here!");
    }
});

Updated JSBin

Upvotes: 1

Related Questions