Fixed multiple list sorting
This commit is contained in:
parent
d0c5127c92
commit
7e9d445051
@ -66,27 +66,31 @@
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
var el = document.querySelector('.task-list');
|
||||
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;
|
||||
var elements = document.querySelectorAll('.task-list').values()
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
// loop through the elements
|
||||
for (let el of elements) {
|
||||
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}, {
|
||||
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