SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.41k stars 3.69k forks source link

Dynamically decide whether element is draggable / droppable #1038

Closed tpraxl closed 7 years ago

tpraxl commented 7 years ago

I'm currently trying to implement the following use case:

I couldn't find a solution yet – maybe I have missed something. Tried to return false in practically every callback function, e.g. onAdd, onChoose, onMove.

Returning false in onMove has an effect, but it only works when sorting items in the target list, it does not prevent dropping items there from another list.

So I also tried to define functions for group put and pull of the respecting groups.

E.g.:

 group: { 
    ///...
    pull: function(e){
        // problem: e provides no information about the list-item to be dragged, only the parent list in e.el
        if(pullAllowed(e)){
            return 'clone';
        }else{
            return false;
        }
    }
}

But I'm only able to gather informations about the parent list from the event object. I would need to identify the item to be dragged in order to decide whether it is allowed to drag it or not.

Does anyone have any hint about how to handle this?

RubaXa commented 7 years ago

https://github.com/RubaXa/Sortable/issues/1037 — ?

tpraxl commented 7 years ago

Thanks for the fast reply, but that doesn't match my usecase as far as I can see.

I need to be able to decide if dragging is allowed, based on the element to drag, not based on the list to drag from. The element may only be present once in the target list.

RubaXa commented 7 years ago

Then I have no idea how to help you.

tpraxl commented 7 years ago

Oh.. how sad.. It's a shame that I can't use sortablejs then. It's nice work.

Well. Thanks anyway for your efforts.

RubaXa commented 7 years ago

Wait, why are onMove is not suitable? http://jsbin.com/jeracer/edit?html,js,output

tpraxl commented 7 years ago

Hey! That's it!

It's not perfect, because I would have preferred to disallow the dragging and not the dropping, but it's the second best approach.

Thank you very much RubaXa! Great.

RubaXa commented 7 years ago

A little imagination and can so: http://jsbin.com/jeracer/edit?html,js,output

tpraxl commented 7 years ago

Great. Thank you very much.

josealonso commented 5 years ago

Wait, why are onMove is not suitable? http://jsbin.com/jeracer/edit?html,js,output

A little imagination and can so: http://jsbin.com/jeracer/edit?html,js,output

Many thanks, RubaXa !! That's exactly what I was looking for.

vedmant commented 1 year ago

This works if all JS code is in one component, in my case I have sortable elements in different components and they don't share the same list property. Is there a method like onMove but called on target sortable?