Giter Site home page Giter Site logo

Cancelling a drop about jquery-sortable HOT 2 CLOSED

johnny avatar johnny commented on July 30, 2024
Cancelling a drop

from jquery-sortable.

Comments (2)

johnny avatar johnny commented on July 30, 2024

This should be possible. But with the current implementation, the drop has already happened at the moment you can check it with onDrop. So there might be a flicker if you remove the item again, after it has been dropped.

This would be a working example:

var backupItem
$("ul").sortable({
  group: 'limited root',
  exclude: ".hidden",
  onDragStart: function (item, container, _super) {
    // Duplicate item
    backupItem = item.clone().insertAfter(item).addClass(".hidden")
    _super(item)
  },
  onDrop: function (item, container, _super) {
    if(itemInRightPlace(item, container)){
      backupItem.remove()
      _super(item)
    } else {
      item.remove()
      backupItem.removeClass(".hidden")
    }
  }
})

But this looks too much like a hack. I might add something more convenient, so please tell me:

Would it be best, if the dragged items would register (aka the red arrow showing) only inside the root ul?

from jquery-sortable.

JgoOrange avatar JgoOrange commented on July 30, 2024

Hi There I am having the same type of issue where onDrop if values are met them the drop is rejected but cannot get the ol to revert back to its original position i have tried the above code but think the issue is that it is already inside of a sortable call. and help would be great.

      `$("ol.left").sortable({
	group: 'nested',
	onDrop: function (event, ui){
		var $this = $('.active');
		var li = $this.parents('li');
                    var ol = $this.parents('ol').parents('ol');
		var div = $this.closest('div');
		li.removeClass("dragged");
		li.removeAttr('style');
             if (($(div).hasClass('left')) && ($(ol).hasClass('left'))) {
                 alert("test");  //code to revert goes here
             } else {
                 update_fs();
             }
	         }
});`

from jquery-sortable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.