Skip to content

Commit

Permalink
added 2nd input element
Browse files Browse the repository at this point in the history
[*] second hidden input element
[*] added a js function to call the click on the hidden input element - this can be done by any custom button
  • Loading branch information
EricRosenfeld1 committed Nov 1, 2019
1 parent 617b655 commit 2dca662
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion BlazorInputFile/InputFile.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
@implements IDisposable
@inject IJSRuntime JSRuntime

<input type="file" @ref="inputFileElement" @attributes="UnmatchedParameters" />
@if (IsElementHidden)
{
<input id="@ElementId" type="file" @ref="inputFileElement" @attributes="UnmatchedParameters" style="display:none;"/>
}
else
{
<input type="file" @ref="inputFileElement" @attributes="UnmatchedParameters" />
}

@code {
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> UnmatchedParameters { get; set; }
[Parameter] public EventCallback<IFileListEntry[]> OnChange { get; set; }
[Parameter] public int MaxMessageSize { get; set; } = 20 * 1024; // TODO: Use SignalR default
[Parameter] public int MaxBufferSize { get; set; } = 1024 * 1024;


[Parameter] public string ElementId { get; set; } // this id is used by the js function 'wrapInput' which calls click()
[Parameter] public bool IsElementHidden { get; set; } = false;

ElementReference inputFileElement;
IDisposable thisReference;

Expand Down
4 changes: 4 additions & 0 deletions BlazorInputFile/wwwroot/inputfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
destinationUint8Array.set(sourceUint8Array, destinationOffset);

return bytesToRead;
},

wrapInput: function wrapInput(elementId) {
document.getElementById(elementId).click();
}
};

Expand Down

0 comments on commit 2dca662

Please sign in to comment.