/*
@multiple - Boolean
@accept - String
A comma separated list of accetable extensions, e.g. ".pdf,.jpg,.jpeg,.png,.gif,.doc,.docx"
*/
export function selectFile(multiple, accept, setFileCb) {
async function runSelectFile(event) {
// Step 2. Upload the files then delete the file input so its not posted
let fileInput = event.target;
const files = fileInput.files; // If multiple attribute was set, files will be a single file
fileInput.remove();
applyFileCallback(files, multiple, setFileCb);
}
// Step 1. Create a temporary input[type="file] widget and click it
let fileInput = document.createElement('input');
fileInput.type = 'file';
multiple && fileInput.setAttribute('multiple', '');
accept && fileInput.setAttribute('accept', accept);
fileInput.addEventListener('change', runSelectFile.bind(this));
fileInput.click();
}
When you run function it bring up the file browser selection, however the minified version, it opens the file browser rwice in chrome. So one selects the file, then the file browser pops up again and one has to cancel it the second time:
export function selectFile(e,n,r){async function i(o){let l=o.target;const g=l.files;l.remove(),s(g,e,r)}let t=document.createElement("input");t.type="file",e&&t.setAttribute("multiple",""),n&&t.setAttribute("accept",n),t.addEventListener("change",i.bind(this)),t.click()}
This code:
Could be used like this:
When you run function it bring up the file browser selection, however the minified version, it opens the file browser rwice in chrome. So one selects the file, then the file browser pops up again and one has to cancel it the second time: