diff --git a/templates/components/scripts.html b/templates/components/scripts.html index f7ae68b..02d18ab 100644 --- a/templates/components/scripts.html +++ b/templates/components/scripts.html @@ -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); + }); + } + }); + } });