diff --git a/caricari/static/form.js b/caricari/static/form.js new file mode 100644 index 0000000..33fb5d5 --- /dev/null +++ b/caricari/static/form.js @@ -0,0 +1,29 @@ +const dropZone = document.getElementById('dropZone') +const formFile = document.getElementById('formFile') + +dropZone.addEventListener('click', () => formFile.click()) + +dropZone.addEventListener('dragover', (e) => { + e.preventDefault() + dropZone.classList.add('bg-light') +}) + +dropZone.addEventListener('dragleave', () => { + dropZone.classList.remove('bg-light') +}) + +dropZone.addEventListener('drop', (e) => { + e.preventDefault() + dropZone.classList.remove('bg-light') + formFile.files = e.dataTransfer.files + updateDropZoneText() +}) + +formFile.addEventListener('change', updateDropZoneText) + +function updateDropZoneText() { + dropZone.textContent = + formFile.files.length > 0 + ? formFile.files[0].name + : 'Drag and drop a file here or click to select' +} diff --git a/caricari/templates/form.html b/caricari/templates/form.html index c181b9a..9de9d74 100644 --- a/caricari/templates/form.html +++ b/caricari/templates/form.html @@ -7,8 +7,11 @@
- +
+Drag and drop a file here or click to select
+
+ {%endblock %}