Skip to content

Sending originalArray and newArray #1806

Open
@beanben

Description

@beanben

Hello hello,

apologies for the basic question but I am using struggling to send the originalArray and the newArray with the new order of the elements.

Any tips welcome !

the JS:

var sortable = Sortable.create(selection, {
  handle: '.bars-move',
  animation: 150,
});

var modalForm = document.getElementById("modalForm");
if (modalForm  !== null ){
  modalForm.addEventListener('submit', function(e) {

    var formData = new FormData(modalForm);
    e.preventDefault();
    var request = new XMLHttpRequest();
    request.open(modalForm.method, modalForm.action, true);
    var cookies = parse_cookies();
    request.setRequestHeader('X-CSRFToken', cookies['csrftoken']);

    // var originalArray = ????;

    var newArray = [...document.querySelectorAll("#selection > tr")].map(el => el.getAttribute("data-id"));
    formData.append('newArray', JSON.stringify(newArray));

    request.send(formData);
  });
};

In the code above, newArray sends the new array - no problem - but I have no idea how to write originalArray.

thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionquestions from the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions