Skip to content

Commit

Permalink
bug fix:
Browse files Browse the repository at this point in the history
bug:
when an item is dragged fast enough before the previous request was
completed, dropping after request completion resulted in the addition
of an extra item to the list.

fix:
disable sortable on End event, and re-enable it on htmx:afterSwap.
  • Loading branch information
mohamedhaddi committed Oct 6, 2023
1 parent d789fa7 commit 8f3665b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions www/content/examples/sortable.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ That's it!
htmx.onLoad(function(content) {
var sortables = content.querySelectorAll(".sortable");
for (var i = 0; i < sortables.length; i++) {
var sortable = sortables[i];
new Sortable(sortable, {
var sortableList = sortables[i];
sortable = new Sortable(sortableList, {
animation: 150,
ghostClass: 'blue-background-class',
filter: ".htmx-indicator",
onMove: function (evt) {
return evt.related.className.indexOf('htmx-indicator') === -1;
},
onEnd: function (evt) {
this.option("disabled", true);
}
});
sortableList.addEventListener("htmx:afterSwap", function() {
sortable.option("disabled", false);
});
}
})

Expand Down

0 comments on commit 8f3665b

Please sign in to comment.