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

Multiple Draggable doesn't work for inserted/created elements via js/jquery #612

Open
eren-algan opened this issue Jun 16, 2024 · 1 comment

Comments

@eren-algan
Copy link

eren-algan commented Jun 16, 2024

When I copy and paste the elements, draggable doesn't work. So I called the variable named DraggableMultiple.init() in my function. it works perfectly for the new added element but the old elements didn'twork. I guess I run the codes multiple time for one element and it became broken.

I wanted to add a video for a good explanation about the problem.

Kayit.2024-06-16.105325.mp4

Which way should I follow to fix this problem? Do you have any recommends?

@eren-algan
Copy link
Author

eren-algan commented Jun 16, 2024

I fixed my problem.

If sortable is already started, I destroy it in my function.

var DraggableMultipleMain = {
    init: function () {
        var e = document.querySelectorAll(".draggable-zone-main");
        if (0 === e.length) return false;
        if (sortableMainInstance) {
            sortableMainInstance.destroy();
        }
        sortableMainInstance = new Draggable.Sortable(e, { 
            draggable: ".draggable-main", 
            handle: ".draggable-main .draggable-handle-main", 
            mirror: { 
                appendTo: "body", 
                constrainDimensions: true 
            } 
        });
    },
};

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