Skip to content

Commit

Permalink
Enable choosing FS input XML files multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Jan 31, 2025
1 parent ad1006b commit b443334
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/javascript/controllers/dropzone_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class extends Controller {
const fileList = document.getElementById('fileList');
const fileCount = document.getElementById('fileCount');

this.allFiles = new DataTransfer();

dropzone.addEventListener('dragover', (e) => {
e.preventDefault();
dropzone.classList.add('border-blue-500', 'border-2');
Expand All @@ -32,16 +34,19 @@ export default class extends Controller {

handleFiles(files) {
const fileInput = document.getElementById('content[]');
fileInput.files = files;

for (const file of files) {
this.allFiles.items.add(file);

const listItem = document.createElement('div');
listItem.textContent = `${file.name} (${this.formatBytes(file.size)})`;
fileList.appendChild(listItem);
}

fileCount.parentElement.classList.remove('hidden');
fileCount.textContent = `${parseInt(fileCount.textContent) + files.length}`;

fileInput.files = this.allFiles.files;
}

formatBytes(bytes) {
Expand Down

0 comments on commit b443334

Please sign in to comment.