-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Ceres445/file-upload
Added file upload script
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
django_simple_bulma/extensions/bulma-file-upload/dist/js/bulma-file-upload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
|