From 2dca6625b63e1283eee73b72f2404a11bb022312 Mon Sep 17 00:00:00 2001 From: Eric Rosenfeld <46537274+r0si@users.noreply.github.com> Date: Fri, 1 Nov 2019 18:20:56 +0100 Subject: [PATCH] added 2nd input element [*] 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 --- BlazorInputFile/InputFile.razor | 13 ++++++++++++- BlazorInputFile/wwwroot/inputfile.js | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/BlazorInputFile/InputFile.razor b/BlazorInputFile/InputFile.razor index 0b37811..b981a2e 100644 --- a/BlazorInputFile/InputFile.razor +++ b/BlazorInputFile/InputFile.razor @@ -1,7 +1,14 @@ @implements IDisposable @inject IJSRuntime JSRuntime - +@if (IsElementHidden) +{ + +} +else +{ + +} @code { [Parameter(CaptureUnmatchedValues = true)] public Dictionary UnmatchedParameters { get; set; } @@ -9,6 +16,10 @@ [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; diff --git a/BlazorInputFile/wwwroot/inputfile.js b/BlazorInputFile/wwwroot/inputfile.js index 13e7ab3..a714a6b 100644 --- a/BlazorInputFile/wwwroot/inputfile.js +++ b/BlazorInputFile/wwwroot/inputfile.js @@ -63,6 +63,10 @@ destinationUint8Array.set(sourceUint8Array, destinationOffset); return bytesToRead; + }, + + wrapInput: function wrapInput(elementId) { + document.getElementById(elementId).click(); } };