From 5b9253d0d24a1201343edee09a1f5c066bdd78e8 Mon Sep 17 00:00:00 2001 From: Ceres Date: Fri, 1 Oct 2021 22:55:08 +0530 Subject: [PATCH] Added file upload script --- .../dist/js/bulma-file-upload.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 django_simple_bulma/extensions/bulma-file-upload/dist/js/bulma-file-upload.js diff --git a/django_simple_bulma/extensions/bulma-file-upload/dist/js/bulma-file-upload.js b/django_simple_bulma/extensions/bulma-file-upload/dist/js/bulma-file-upload.js new file mode 100644 index 0000000..12236b2 --- /dev/null +++ b/django_simple_bulma/extensions/bulma-file-upload/dist/js/bulma-file-upload.js @@ -0,0 +1,33 @@ +// Code from https://gist.github.com/micti/bca582bc4054ca7b034faea56930221c +// Make the bulma file upload work out of the box + +document.addEventListener('DOMContentLoaded', () => { + // 1. Display file name when select file + let fileInputs = document.querySelectorAll('.file.has-name') + for (let fileInput of fileInputs) { + let input = fileInput.querySelector('.file-input') + let name = fileInput.querySelector('.file-name') + input.addEventListener('change', () => { + let files = input.files + if (files.length === 0) { + name.innerText = 'No file selected' + } else { + name.innerText = files[0].name + } + }) + } + + // 2. Remove file name when form reset + let forms = document.getElementsByTagName('form') + for (let form of forms) { + form.addEventListener('reset', () => { + console.log('a') + let names = form.querySelectorAll('.file-name') + for (let name of names) { + name.innerText = 'No file selected' + } + }) + } + }) + +