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

Pull revert Or Limit number of items #1877

Closed
LukeTOBrien opened this issue Aug 7, 2020 · 2 comments
Closed

Pull revert Or Limit number of items #1877

LukeTOBrien opened this issue Aug 7, 2020 · 2 comments
Labels
question questions from the community

Comments

@LukeTOBrien
Copy link

LukeTOBrien commented Aug 7, 2020

Hello chaps.

I Have two containers, A and B, containers B is empty and I want to choose one item from container A and drag it inside.
Container B can only have one item inside, so therefore I either want to swap the item being dragged with the item already in the container or I want to revert on pull so that no item is dragged into container B but the onEnd event still fires.

I am using a framework which means that the text of container B is bound to the object I am creating, so I don't need the dragged item to stay in place.
So in my lil app I am creating an appointment, I have a list of doctors and a list of patients, and the appointment with a placeholder for each, but when I drag I can keep on adding to the placeholders.

I can create a CodePen if that will help illustrate.

Thanks

@waynevanson
Copy link
Contributor

You might be able to use onMove on Container A option to your advantage.
When dragging an item to container B, you need to check if it's container B and if >= 1 elements exist, return false from the onMove function.

That will mean that the item will not move to Container B and it will work as you please.

@waynevanson waynevanson added the question questions from the community label Aug 31, 2020
@LukeTOBrien
Copy link
Author

This is what I did in the end:
So you can only drag onto an empty list.

put: function(to) {
  return to.el.children.length == 0;
}

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

No branches or pull requests

2 participants