views:

52

answers:

2

I have a draggable (jquery-ui) element. How can I cancel current draggig based on some constraints? In other words, I want to constraint possible moves of this draggable element, but it is more complicated then based only on axis or parent (containment).

How can I do that?

A: 

Are you looking for disable? http://docs.jquery.com/UI/Draggable#methods

Simeon
No, I am not looking for disable method. When you call disable, current dragging still occurs. Only the next dragging attempts are disabled.
JohnM2
+1  A: 

You can't cancel the drop it seems. Only solution I have so far is to redraw the all the draggables...

This is for applying a confirmation dialog to the drop and goes something like:

fruitbowl.draw()   // my routine which puts draggable elements into the DOM

$("trash").droppable({
    drop: function(ev, ui){
        $("#areyousure-dialog")
                .data('fruit',ui.draggable)  // passes the dragged el
                .dialog("open")
    }
}

$("#areyousure-dialog").dialog({
    buttons: {
        'Yes I\'m sure': function(){
              var fruit = $(this).data('fruit') 
              fruit.remove()
              fruitbowl.draw() 
              $(this).removeData('fruit').dialog('close')
         },
         Cancel: function(){
              fruitbowl.draw()
              $(this).removeData('fruit').dialog('close')
         }
 }

Open to improvements, not sure if that's the best way to pass the dropped element to the dialog, but works for me.

John Mee