Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: When dragging between lists, a shadow element is kept in the pulled list. #1091

Closed
pedroadame opened this issue Apr 19, 2017 · 2 comments

Comments

@pedroadame
Copy link

pedroadame commented Apr 19, 2017

I want to have three lists, one, two, and central. You can rearrange items between lists but you cannot have more than 5 items or less than one in one and two. I used a put/pull function to handle this, but it doesn't work and I don't know what I'm doing wrong.

JSFiddle: http://jsbin.com/juwicom/4/edit?html,js,console,output
Steps to reproduce:

  1. Drag One 2 and One 3 to the Two X list.
  2. You cannot drag One 1 into Two X list because it is the last item of its list -- OK
  3. You cannot drag Central 1 into Two X list because Two X list already contains 5 items. -- OK
  4. Drag One 2 and One 3 again to the One 1 list.
  5. Now, you cannot drag any more items to One X list or Two X list, including the Central 1 item.
  6. In fact, if you drag One X or Two X to central list, you cannot redrag it to the original list.

This is the function I used in the pull option for groupone and grouptwo in the fiddle:

    pull: function (from, to) {
      return from.el.children.length > 1;
    },
    put: function(to) {
      return to.el.children.length < 5;
    }

Is my function wrong? @RubaXa

Update

  1. Inspect foo list and you will see ghost elements with display: none of the elements you dragged before. Then, as there are 5 items, you cannot drag into the list.

You can see this in your own advanced usage of group fiddle: http://jsbin.com/rusuvot/edit?js,output Just inspect qux and drag to that list. Then drag outside. A ghost item is kept there.

@pedroadame pedroadame changed the title Bug? Pull function doesn't work properly with from.el.children.length Bug: When dragging between lists, shadow element is kept in lists. Apr 19, 2017
@pedroadame pedroadame changed the title Bug: When dragging between lists, shadow element is kept in lists. Bug: When dragging between lists, a shadow element is kept in the pulled list. Apr 19, 2017
@pedroadame
Copy link
Author

Bug workaround:

Sortable.create(list, {
onRemove: function(evt){
    var ch = evt.from.children;
    for(var i = 0; i < ch.length; i++){
      var element = ch[i];
      if(window.getComputedStyle(element).getPropertyValue('display') == 'none'){
        element.parentNode.removeChild(element);
      }
    }
  }
}

@pedroadame
Copy link
Author

Fixed in 1.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant