diff --git a/LiftLog.Ui/Shared/Presentation/EditableIncrementer.razor b/LiftLog.Ui/Shared/Presentation/EditableIncrementer.razor index fa2c6aba..6fb8af7e 100644 --- a/LiftLog.Ui/Shared/Presentation/EditableIncrementer.razor +++ b/LiftLog.Ui/Shared/Presentation/EditableIncrementer.razor @@ -11,7 +11,6 @@ @code { - [Parameter] [EditorRequired] public T Value { get; set; } = default!; [Parameter] [EditorRequired] public T Increment { get; set; } = default!; @@ -27,7 +26,7 @@ private void OnChanged(string? value) { - if (value != null && T.TryParse(value, System.Globalization.NumberStyles.Any, + if (value != null && T.TryParse(value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentCulture, out var result)) { OnChange(result); diff --git a/LiftLog.Ui/Shared/Presentation/TextField.razor b/LiftLog.Ui/Shared/Presentation/TextField.razor index 33106822..91dc705f 100644 --- a/LiftLog.Ui/Shared/Presentation/TextField.razor +++ b/LiftLog.Ui/Shared/Presentation/TextField.razor @@ -3,12 +3,12 @@ @switch (TextFieldType) { case TextFieldType.Outline: - OnChange?.Invoke((string)e.Value!)) @onfocusin=SelectOnFocus @onclick=OnClick> + OnChange?.Invoke((string?)e.Value!)) @onfocusin=SelectOnFocus @onclick=OnClick @onblur=@(_=>SetValueOnElement())> @ChildContent break; case TextFieldType.Filled: - OnChange?.Invoke((string)e.Value!)) @onfocusin=SelectOnFocus @onclick=OnClick> + OnChange?.Invoke((string?)e.Value!)) @onfocusin=SelectOnFocus @onclick=OnClick @onblur=@(_=>SetValueOnElement())> @ChildContent break; @@ -33,7 +33,7 @@ protected override async Task OnParametersSetAsync() { - await JSRuntime.InvokeVoidAsync("AppUtils.setValue", _textField, Value); + await JSRuntime.InvokeVoidAsync("AppUtils.setValueIfNotFocused", _textField, Value); await base.OnParametersSetAsync(); } @@ -42,4 +42,9 @@ await JSRuntime.InvokeVoidAsync("AppUtils.selectAllText", _textField); } + private async Task SetValueOnElement() + { + await JSRuntime.InvokeVoidAsync("AppUtils.setValue", _textField, Value); + } + } diff --git a/LiftLog.Ui/wwwroot/app-utils.js b/LiftLog.Ui/wwwroot/app-utils.js index c0ba8eb9..d1edab3e 100644 --- a/LiftLog.Ui/wwwroot/app-utils.js +++ b/LiftLog.Ui/wwwroot/app-utils.js @@ -58,6 +58,11 @@ AppUtils.setValue = function (element, value) { element.value = value; } +AppUtils.setValueIfNotFocused = function (element, value) { + if (element && document.activeElement !== element) + element.value = value; +} + AppUtils.getValue = function (element) { return element.value; }