JQuery sortable ('disable') from start event does not work fully as expected

In the code below, sorting in the start event is not completely disabled. It will add the ui-sortable-disabled and ui-state-disabled classes to the elements to be sorted, but it will not disable the functionality - in other words, the sorts look disabled, but they still accept the dragged item and behave as if they were enabled.

 var assignedSortables; var startDrag = function(event, ui) { assignedSortables.each(function() {$(this).sortable('disable');}); }; var stopDrag = function(event, ui) { assignedSortables.each(function() {$(this).sortable('enable');}); }; assignedSortables = $(".my-sortable-containers").sortable({ connectWith: '.my-sortable-containers', start: startDrag, stop: stopDrag }); 

The reason I want to do this is to start dragging, because I may need to disable other related sorts that already contain the item that is being dragged (I simplified the logic to simplify). Is this a mistake or is there a way around this?

+4
source share
2 answers

I did not check if the jQuery library has “fixed”, since I asked what I did instead, use the mousedown and mouseup events to turn it off and on

 $(".myDraggableContainer").mousedown(functionToDisableTheCorrectSortables).mouseup(functionToEnableSortables); 

Performing this method really completely disables the resulting sorts.

+4
source

I just ran into the same problem. I was able to get a related sort that I wanted to disable in order to disable (for real) by calling the refresh method to initiate sorting.

So, inside your initial callback there will be something like:

 $connectedList.sortable('disable'); $(ui.sender).sortable('refresh'); 

I assume that from inside the list captures a set of connected and non-disconnected lists before the launch event is triggered and does not check if this list has changed after the launch.

+7
source

All Articles