views:

646

answers:

4

The below code does not fully disable the sortables on the start event. It will add the classes "ui-sortable-disabled" and "ui-state-disabled" to the sortable elements, but it doesn't disable the functionality - in other words, the sortables look disabled, but they still accept the dragged item and behave like they are 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 on drag start is because I might need to disable other connected sortables that already contain the item being dragged (I stripped out the logic in order to simplify). Is this a bug or is there a way around it?

A: 

Can you Remove the drag handlers in addition to changing the class?

Michael
It's not that I don't want it to be draggable, it is that I might only want certain connected sortables to _not_ accept the item I'm dragging. I figured disabling them would be the most straightforward and user-friendly way.
jayrdub
A: 

I'm trying to do the same thing, to avoid people making an object in a hierarchy a child of itself. I've tried sortable('destroy') in addition to sortable disable.

Jesse P
A: 

I am looking to do exactly that, no luck so far..
Right now I use the receive method that removes the item after being dropped but I would like to disable my connected list on start

Did you figure it out at the end?

FFish
I answered your question about how I got around it
jayrdub
+1  A: 

I have not checked to see if the jQuery library has "fixed" this since I asked the question, what I did instead was use the mousedown and mouseup events to disable and enable

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

Doing it this way does in fact disable the receiving sortables fully

jayrdub
Hi! I was just playing around with hiding the .placeholder in the over event, but it's just a visual hack, I still need to remove the item etc. I tried your answer but can't get it to work? See my Fiddle: http://jsfiddle.net/tunafish/m32XW/1/ What am I missing? In this example I just want to disable the right list when dragging items from the left.
FFish
Got it now!! I was doing the mouse events on the list not the items. See: http://jsfiddle.net/tunafish/m32XW/3/ What a relief, now I can get of my crazy hacks :-) *Bounty* cheers
FFish
Awesome, nice job
jayrdub