Skip to content
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

chapter 13. error in cycle at script #55

Open
msgtv opened this issue Oct 18, 2023 · 0 comments
Open

chapter 13. error in cycle at script #55

msgtv opened this issue Oct 18, 2023 · 0 comments

Comments

@msgtv
Copy link

msgtv commented Oct 18, 2023

sorry for my english
on chapter 13 when adding eventlistener 'sortupdate' fetch query sends every run on cycle:

sortable('#course-modules', {
          forcePlaceholderSize: true,
          placeholderClass: 'placeholder'
        })[0].addEventListener('sortupdate', function(e) {
          modulesOrder = {};
          var modules = document.querySelectorAll('#course-modules li');
          modules.forEach(function (module, index) {
            modulesOrder[module.dataset.id] = index;
            module.querySelector('.order').innerHTML = index + 1;
            options['body'] = JSON.stringify(modulesOrder);
            fetch(moduleOrderUrl, options);
          });
        });

. it is not right.
Right:

sortable('#course-modules', {
          forcePlaceholderSize: true,
          placeholderClass: 'placeholder'
        })[0].addEventListener('sortupdate', function(e) {
          modulesOrder = {};
          var modules = document.querySelectorAll('#course-modules li');
          modules.forEach(function (module, index) {
            modulesOrder[module.dataset.id] = index;
            module.querySelector('.order').innerHTML = index + 1;
          });
          options['body'] = JSON.stringify(modulesOrder);
          fetch(moduleOrderUrl, options);
        });

fetch query must be send when cycle is finish!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant