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

Moving between lists doesn't call Store set callback of receiving list #1352

Closed
furnaceX opened this issue Aug 6, 2018 · 1 comment
Closed

Comments

@furnaceX
Copy link

furnaceX commented Aug 6, 2018

When dragging an element from one list to a second list, the Store "set" callback is called of the originating list, but not on the receiving list. This results in a the "order" array of the receiving list not being updated, so you don't have an accurate variable with the most current order. (as soon as you move items withing that "receiving" list, the order will be updated. But if you use the order variable without moving something, it will be incorrect.

I was able to overcome this by adding an "onAdd" callback in the Sortable setup:

onAdd: function (evt)  {
      orderq.splice(evt.newIndex, 0, evt.item.getAttribute("data-id"));
  },

Here is my jsbin.

Perhaps this is the intended design or I'm using this library incorrectly, so I wouldn't necessarily call this a bug.

Also, I should note that it is important to initialize the "order" arrays properly, otherwise they start as undefined. For example, include the "get" callback function below:

  store: {
    get: function(sortable){
      orderq = sortable.toArray();
      return orderq;
    },
    set: function(sortable) {
      orderq = sortable.toArray();
    }
  },

Lastly, it seems a bit overkill that I return the "order" array in the get function since it is just setting the order to the current order. I can remove the "return" statement and everything will work. But I do get one error in the console: "TypeError: order is undefined" at line 1057 of Sortable.js. I've submitted a pull request to fix this.

@owen-m1
Copy link
Member

owen-m1 commented Dec 16, 2018

Solved in 1.8.0-rc1.

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

2 participants