Fixed multiple list sorting
This commit is contained in:
parent
d0c5127c92
commit
7e9d445051
@ -66,27 +66,31 @@
|
|||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', (event) => {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
var el = document.querySelector('.task-list');
|
var elements = document.querySelectorAll('.task-list').values()
|
||||||
Sortable.create(el, {
|
|
||||||
handle: '.drag-handle',
|
|
||||||
animation: 150,
|
|
||||||
onEnd: function (evt) {
|
|
||||||
var habitId = el.children[evt.newIndex].id.split('-')[1];
|
|
||||||
var oldIndex = evt.oldIndex;
|
|
||||||
var newIndex = evt.newIndex;
|
|
||||||
|
|
||||||
axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, {
|
// loop through the elements
|
||||||
headers: {
|
for (let el of elements) {
|
||||||
'Content-Type': 'application/json'
|
Sortable.create(el, {
|
||||||
}
|
handle: '.drag-handle',
|
||||||
}).then(function (response) {
|
animation: 150,
|
||||||
// Handle the success response if needed
|
onEnd: function (evt) {
|
||||||
}).catch(function (error) {
|
var habitId = el.children[evt.newIndex].id.split('-')[1];
|
||||||
// Handle the error if needed
|
var oldIndex = evt.oldIndex;
|
||||||
console.error('Error:', error);
|
var newIndex = evt.newIndex;
|
||||||
});
|
|
||||||
}
|
axios.post('/reorder', {habitId: habitId, oldIndex: oldIndex, newIndex: newIndex}, {
|
||||||
});
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}).then(function (response) {
|
||||||
|
// Handle the success response if needed
|
||||||
|
}).catch(function (error) {
|
||||||
|
// Handle the error if needed
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user