Search code examples
jqueryjquery-uidraggabledroppable

Why I can disable, but can't enable a droppable function?


I need only 1 block in one drop-area and switch if needed. Why I can disable, but can't enable a droppable function?

Here is my code:

$('.my_block').draggable({
    revert: "invalid",        
});

$('.free').droppable({         
    accept: ".my_block",
    drop: function(ev, ui) {             
        $(this).removeClass("free");    
        $(this).addClass("1");                
        ui.draggable.appendTo($(this)).removeAttr('style');
            $(this).droppable("disable");              
        },
        out:  function(ev, ui) {                     
            $(this).droppable("enable");    
            $(this).removeClass("1");    
            $(this).addClass("free");            
        },        
    });

jsfiddle http://jsfiddle.net/4ABCN/2/

And how can I back all red blocks to main positions by one button?


Solution

  • Working demo Deleted old demo

    New Demo Try this: http://jsfiddle.net/7EbKS/

    Behaviour: Now when user moves the red box you are allowed to drop another one in empty position,

    Hope it fits the cause :)

    Code

      $(function() {
        foo();
    
        $('.my_block').draggable({
            revert: "invalid",
            stop: function() {
                $(this).draggable('option', 'revert', 'invalid');
            }
    
        });
    
        function foo() {
            $('.block').droppable({
                greedy: true,
                accept: ".my_block",
                // tolerance: "fit",
                drop: function(ev, ui) {
                    ui.draggable.appendTo($(this)).removeAttr('style');
                 }
            });
        }
        $('.my_block').droppable({
            greedy: true,
            tolerance: 'touch',
            drop: function(event, ui) {
                ui.draggable.draggable('option', 'revert', true);
            }
        });
    
    });