html5sortable icon indicating copy to clipboard operation
html5sortable copied to clipboard

ability for 'acceptFrom' to accept a function as an argument

Open mike16889 opened this issue 4 years ago • 5 comments

I came across a need to be able to decide if a specific item should be accepted or not, with jQuery UI, it can be done with a function on 'accept' option which for me, works perfect, the only piece of jQuery UI i use is sortable and that has bugs and looks to no longer be maintained so I wanted to use this library.

but that functionality is not available, so I figured I would see if I can hack that functionality into html5sortable (which I am really loving btw)

You will have to excuse me as I am a bit of a novice and do not know how to use git or buildtools.

I modified _listsConnected to accept destination and dragging instead of destination and origin (origin = dragging.parentElement), that way the user supplied function can be passed the item being dragged for evaluation.

HERE is a codepen with a working example:

mike16889 avatar Jan 22 '21 02:01 mike16889

Hey, that sounds great.

Would you be able to send a PR to include this? I am not 100% sure what you changed exactly, but if you send it via a PR I can see the changes and we can discuss how to best integrate it.

lukasoppermann avatar Jan 22 '21 08:01 lukasoppermann

Isn't this what items: ':not(.disabled)' is for? Or in your case it would be:

sortable(".sortable1", {
  acceptFrom: ".sortable1, .sortable2",
  items: ':not([data-cansort="no"])'
});
sortable(".sortable2", {
  acceptFrom: ".sortable1, .sortable2"
});

Barabazs avatar Jan 30 '21 11:01 Barabazs

@Barabazs @mike16889 the way I understood it, the function can be used for more complex filtering. E.g. you could check if an item is a specific type, if the text of an item starts with a # or anything you would like.

It basically allows for more flexibility.

lukasoppermann avatar Jan 30 '21 11:01 lukasoppermann

@Barabazs @lukasoppermann exactly, you could have it check just about anything, you could have it so a sortable will only accept a drop on every even minute, or only while a specific key is held down.

mike16889 avatar Jan 30 '21 11:01 mike16889

Thank you for clarifying. That would be a nice addition and I actually might have a use-case for it.

Barabazs avatar Jan 30 '21 13:01 Barabazs