Skip to content Skip to sidebar Skip to footer

Is There A Way To Revert The Jquery Drag-drop Draggable To Its Original Position If It Fails Validation?

I am trying to understand how to get this to work and I am unsure... I have multiple parent divs (the droppables) and multiple child divs (the draggables). The child divs contain a

Solution 1:

See this question: how to revert position of a jquery UI draggable based on condition

You need to instruct JQuery to revert the draggable div if some rule is not met.

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

Then in your .droppable() sets what is valid for a drop using the accept option, for example:

$(".parent").droppable({ 
    accept: function(dropElem) {
      //dropElem was the dropped element, return true or false to accept/refuse itreturn ($(dropElem).hasClass("child") && $("input",dropElem).val().length > 0);
    },
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    tolerance:'pointer',
    drop: function( event, ui ) {
        $( this )
            .addClass( "ui-state-highlight" )
            .find( "p" )
            .append(ui.draggable).animate({width:'100',height:'100'});
    }
});

Post a Comment for "Is There A Way To Revert The Jquery Drag-drop Draggable To Its Original Position If It Fails Validation?"