-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
how to cancel drop in onEnd? #837
Comments
You can't cancel drop in onEnd statement because the element was dropped. You can try to pass |
Nohow. |
Would be nice to see a comment about what the recommended approach would be for this. I'm using sortable within Aurelia and had all sort of issues Aurelia was causing because sortable changes the dom. I'd rather cancel the move/add and just update the arrays and let Aurelia update its bindings. |
Same here. I'm using Aurelia and would like to use Sortable in my projects. Really need the cancelation of dom manipulation. |
I ended up switching to Dragula for the time being, until we can have some additional functionality on Sortable. |
Haha... funny things, I've been using Dragula since I started working with Aurelia but would like to switch to Sortable now and find out it's hard without ugly hacks... Will probably end up doing same as you! Thanks for your heads up! |
I am also looking for this functionality. Might go with Dragula as well. |
I am using Sortable to drop elements across sortable lists. I was able to do this by explicitly removing the child element from DOM in
I'm using Sortable with VueJS and wasn't sure of using vue-draggable yet. This is still WIP and my model binding is flaky as of now, but I needed a quick way to retain DOM control entirely with Vue while extracting essential data from the event. I don't like this solution but it does the job ATM. Hope this helps someone. |
if anyone is still looking for a solution, |
I have also encountered this problem in Vue, my situation is:
And still looking for good solution also. |
I found out that it is possible to cancel in onMove |
If anyone else is looking for a solution, I used the onMove and put a class on the first element ignore-drag. Then used this code to cancel the move if class existed on the hovered element. So this works also if you wish to be able to lock the last element etc.
|
I found a similiar solution to @xyyVee, but made some small tweeks so that it only uses the
|
Try this: Support also for nested items onEnd (e) {
let condition = true // Your condition here
if (condition) {
const items = e.from.querySelectorAll(':scope > div') // You can change this if needed (example: draggable: '.my-item' change to :scope > .my-item)
e.from.insertBefore(e.item, items[e.oldIndex + (e.oldIndex > e.newIndex)])
return false
}
} |
I too needed to prevent changing the DOM to work with lit.dev This seems to be working well for me: onChoose(e){
e.item.placeholder = document.createComment('sort-placeholder')
e.item.after(e.item.placeholder)
},
onSort(e){
// put back in original location
if( e.item.placeholder ){
e.item.placeholder.replaceWith(e.item)
delete e.item.placeholder
}
// add your logic to save sort and update DOM
} |
found a solution here |
For lit.dev users, check #2089 for more lit.dev targeted solutions. |
I'm trying to use sortable with aurelia. I want to prevent changing DOM by sortable. Is there a way to cancel drop in onEnd?
The text was updated successfully, but these errors were encountered: