I have a file input like this:
<lightning:input aura:id="fileInput"
type="file"
label="{!v.label}"
name="file"
multiple="true"
accept="{!v.accept}"
files="{!v.files}" />
And I want to have a button to clear the selected files after upload. The old answer is to do this:
component.find('fileInput').getElement().value='';
But, quite correctly, Locker Service won't let me go poking at the DOM inside the lightning
namespace.
So, I might try setting v.files
to null
.
component.find('fileInput').set('v.files', null);
That does clear them, but when you select some more files, they don't get returned properly into v.files
.
v.files
is actually a FileList, which I cannot construct directly, or modify reliably. That seems to be why just zapping it with null
breaks the file input.
It looks a lot like I'm stuck at another Lightning dead end... Any ideas?
component.find('fileInput').set('v.files', []);