Skip to content

Commit

Permalink
Select the amount field when opening the create/edit expense dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
esond committed Mar 21, 2024
1 parent b1eacf0 commit e088096
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Clients/App/Components/Expenses/ExpenseForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

<MudGrid>
<MudItem xs="6">
<MudNumericField @bind-Value="Expense.Amount"
<MudNumericField @ref="AmountFieldRef"
@bind-Value="Expense.Amount"
T="decimal"
Label="Amount"
HelperText="The expense amount"
Step="1m"
Min="0.00m"
Max="999999.99m"
Required
AutoFocus
For="@(() => Expense.Amount)"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Rounded.AttachMoney"/>
Expand Down
10 changes: 9 additions & 1 deletion src/Clients/App/Components/Expenses/ExpenseForm.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.InteropServices.JavaScript;
using Fluxor;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using Spenses.App.Store.ExpenseCategories;
using Spenses.App.Store.Expenses;
using Spenses.App.Store.Homes;
Expand Down Expand Up @@ -34,6 +35,8 @@ public partial class ExpenseForm

private IEnumerable<string> AvailableTags => ExpensesState.Value.ExpenseFilters.Tags;

private MudNumericField<decimal> AmountFieldRef { get; set; } = new();

private DateTime? DateValue
{
// Return null if the date isn't set yet. Workaround for making the start month of the date picker work
Expand All @@ -58,11 +61,16 @@ private void OnTagValueChanged(string tag)

protected override void OnInitialized()
{
base.OnInitialized();
base.OnInitializedAsync();

Dispatcher.Dispatch(new ExpenseCategoriesRequestedAction(Home.Id));
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await AmountFieldRef.SelectAsync();
}

private Task<IEnumerable<string>> SearchTags(string value)
{
if (string.IsNullOrEmpty(value))
Expand Down

0 comments on commit e088096

Please sign in to comment.