rejetto forum

no jquery

0 Members and 1 Guest are viewing this topic.

Offline NaitLee

  • Tireless poster
  • ****
    • Posts: 203
  • Computer-brain boy
    • View Profile
(Going to make multi-file select to Takeback. Almost done.)
A question: in a folder, after getting (only) selected filenames, how to archive them without jQuery?
"Computation is not forbidden magic."
Takeback Template | PHFS


Offline NaitLee

  • Tireless poster
  • ****
    • Posts: 203
  • Computer-brain boy
    • View Profile
A question: in a folder, after getting (only) selected filenames, how to archive them without jQuery?

This can be done with:

Code: [Select]
// Get all selected filenames as array(list) variable "filenames"
if (!confirm('{.!Download these.} '+filenames.length+' {.!files in a .tar archive?.}')) return;
var form = document.createElement('form');
form.style.display = 'none';
form.action = '%folder%?mode=archive&recursive';
form.method = 'POST';
filenames.forEach(function(v, i) {
    form.append(document.createElement('input'));
    form.children[i].type = 'hidden';
    form.children[i].name = 'selection';
    form.children[i].value = v;
})
document.body.appendChild(form);
form.submit();
"Computation is not forbidden magic."
Takeback Template | PHFS


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
yeah, my code was just for collecting the filenames.
i still would change this:
Code: [Select]
form.append(document.createElement('input'));
    form.children[i].type = 'hidden';
    form.children[i].name = 'selection';
    form.children[i].value = v;

into this:
Code: [Select]
form.append(Object.assign(document.createElement('input'), { type:'hidden', name:'selection', value:v }));


Offline dj

  • Tireless poster
  • ****
    • Posts: 291
  • 👣 🐾
    • View Profile
    • PWAs