Skip to content

Pull revert Or Limit number of items #1877

Closed

Description

@LukeTOBrien

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

Activity

  1. waynevanson commented on Aug 31, 2020

    @waynevanson
    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.

  2. LukeTOBrien commented on Sep 4, 2020

    @LukeTOBrien
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionquestions from the community

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions