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

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

Open
mike16889 opened this issue Jan 22, 2021 · 5 comments · May be fixed by #646
Open

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

mike16889 opened this issue Jan 22, 2021 · 5 comments · May be fixed by #646

Comments

@mike16889
Copy link
Contributor

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:

@lukasoppermann
Copy link
Owner

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.

@Barabazs
Copy link
Contributor

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"
});

@lukasoppermann
Copy link
Owner

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

@mike16889
Copy link
Contributor Author

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

@Barabazs
Copy link
Contributor

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

@lukasoppermann lukasoppermann linked a pull request Jan 31, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants