diff --git a/REMAN/REMAN/JsFunctions.cs b/REMAN/REMAN/JsFunctions.cs new file mode 100644 index 0000000..a6ab6a2 --- /dev/null +++ b/REMAN/REMAN/JsFunctions.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace REMAN +{ + public static class JsFunctions + { + public static async Task FocusAsync(this ElementReference elementRef, IJSRuntime jsRuntime) + { + await jsRuntime.InvokeVoidAsync("Js.focus", elementRef); + } + } +} diff --git a/REMAN/REMAN/Pages/PickUp.razor b/REMAN/REMAN/Pages/PickUp.razor index 504e94e..2839458 100644 --- a/REMAN/REMAN/Pages/PickUp.razor +++ b/REMAN/REMAN/Pages/PickUp.razor @@ -4,6 +4,7 @@ @using NKC.Data.DbModels @using REMAN.Components @using REMAN.Data +@using static JsFunctions @inject AuthenticationStateProvider AuthStateProvider @inject IJSRuntime JSRuntime @@ -11,6 +12,7 @@ PickUp +
@@ -28,7 +30,7 @@
- +
@if (!string.IsNullOrEmpty(lastCmd)) { @@ -39,11 +41,15 @@
@if (!string.IsNullOrEmpty(alertMessage)) { -
@alertMsg
+
+ @alertMsg +
} @if (!string.IsNullOrEmpty(lastMessage)) { -
@lastMsg
+
+ @lastMsg +
}
@@ -52,6 +58,8 @@ @code { + private ElementReference CodeInput; + private bool processing = false; private string alertMessage = ""; private string lastMessage = ""; @@ -89,6 +97,19 @@ await ReloadData(); } + protected async override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await SetFocusAsync(); + } + } + + public async Task SetFocusAsync() + { + await CodeInput.FocusAsync(JSRuntime); + } + protected async Task processInput(string inputVal) { inputVal = inputVal.Trim(); @@ -105,10 +126,21 @@ else { alertMessage = $"Error: code {inputVal} not valid / not found"; + lastCmd = ""; + await waitResetAlerts(); } processing = false; } + private async Task waitResetAlerts() + { + //await Task.Delay(1); + //await InvokeAsync(StateHasChanged); + //await Task.Delay(1); + //await Task.Delay(3000); + //await ReloadData(); + } + private async Task ReloadData() { currRecord = null; @@ -116,6 +148,7 @@ lastMessage = ""; lastCmd = ""; await Task.Delay(1); + //await Focus("CodeInput"); } protected string currUserId diff --git a/REMAN/REMAN/Pages/_Host.cshtml b/REMAN/REMAN/Pages/_Host.cshtml index cc30c30..d0500cf 100644 --- a/REMAN/REMAN/Pages/_Host.cshtml +++ b/REMAN/REMAN/Pages/_Host.cshtml @@ -6,3 +6,4 @@ } + diff --git a/REMAN/REMAN/wwwroot/js/blazorSupport.js b/REMAN/REMAN/wwwroot/js/blazorSupport.js new file mode 100644 index 0000000..fc34f25 --- /dev/null +++ b/REMAN/REMAN/wwwroot/js/blazorSupport.js @@ -0,0 +1,5 @@ +window.Js = { + focus: function (element) { + setTimeout(() => { element.focus(); }, 250); + } +} \ No newline at end of file