Created
November 20, 2018 20:17
-
-
Save brianmriley/726090f977eb7aa2dcca28209f266612 to your computer and use it in GitHub Desktop.
Demonstrates how one can programmatically set a HTML file input's value.
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
// Taken from SO: https://stackoverflow.com/questions/47119426/how-to-set-file-objects-and-length-property-at-filelist-object-where-the-files-a | |
const dT = new ClipboardEvent('').clipboardData || // Firefox < 62 workaround exploiting https://bugzilla.mozilla.org/show_bug.cgi?id=1422655 | |
new DataTransfer(); // specs compliant (as of March 2018 only Chrome) | |
dT.items.add(new File(['foo'], 'programmatically_created.txt')); | |
inp.files = dT.files; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment