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

[bug] Can't exclude item from being sortable and drop target #2014

Closed
miro-ux opened this issue Mar 12, 2021 · 1 comment
Closed

[bug] Can't exclude item from being sortable and drop target #2014

miro-ux opened this issue Mar 12, 2021 · 1 comment

Comments

@miro-ux
Copy link

miro-ux commented Mar 12, 2021

Trying to exclude an item from being draggable works but not from being sortable -- the problem is that other elements can be placed behind it.

Here's the expected behavior using jQuery UI:
http://jsfiddle.net/mirohristov/gn3r2ax4/
Notice that you can never place an item after the last "Add New Item".
This is another example using jQuery UI that makes distinction between sortable and drop target and can disable it either one.

What I've tried so far:
http://jsfiddle.net/mirohristov/69bfknzg/
Notice that you can drag another element behind the "Add New Item"

Following comments in this issue I've tried to use onMove to no avail:

        onMove: function(evt){
          return $(evt.dragged).is(':last-child') ? false : true; //doesn't work
        }

I don't want to take the "Add New Item" out of the sortable div.
Any idea how to accomplish this?

Thanks!

@miro-ux miro-ux changed the title [feature] Can't exclude item from being sortable and drop target [bug] Can't exclude item from being sortable and drop target Mar 12, 2021
@miro-ux
Copy link
Author

miro-ux commented Mar 13, 2021

This has been resolved here: https://stackoverflow.com/a/66610468/559079

A class .exclude is added to the desired element then a combination of filter and onMove

let mySortable = $(".sortable").sortable({
  filter: ".exclude", //Excludes element - similar to `:not()`
  onMove: function(evt) {
    return evt.related.className.indexOf('exclude') === -1; // returns false when the .exclude is about to be moved
  }
});

Note: I do feel like this should be the default behavior for filtered items

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