From e0652a5e41bb3c8a173668ec46d2ef621b6f613b Mon Sep 17 00:00:00 2001 From: Liam Morrow Date: Fri, 15 Nov 2024 18:23:43 +1100 Subject: [PATCH] Correctly manage values on select field --- .../BackupAndRestore/PlainTextExportPage.razor | 8 ++++---- LiftLog.Ui/Shared/Presentation/SelectField.razor | 15 +++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/LiftLog.Ui/Pages/Settings/BackupAndRestore/PlainTextExportPage.razor b/LiftLog.Ui/Pages/Settings/BackupAndRestore/PlainTextExportPage.razor index 694bc3c5..c3716de1 100644 --- a/LiftLog.Ui/Pages/Settings/BackupAndRestore/PlainTextExportPage.razor +++ b/LiftLog.Ui/Pages/Settings/BackupAndRestore/PlainTextExportPage.razor @@ -15,7 +15,7 @@ - + @@ -27,7 +27,7 @@ @code { private PlaintextExportFormat Format = PlaintextExportFormat.CSV; - private List.SelectOption> Formats = [new("CSV", PlaintextExportFormat.CSV)]; + private List Formats = Enum.GetValues().Select(x=>new SelectField.SelectOption(x.ToString(), x.ToString())).ToList(); protected override void OnInitialized() { @@ -36,9 +36,9 @@ base.OnInitialized(); } - private void SelectFormat(PlaintextExportFormat format) + private void SelectFormat(string format) { - Format = format; + Format = Enum.Parse(format); StateHasChanged(); } diff --git a/LiftLog.Ui/Shared/Presentation/SelectField.razor b/LiftLog.Ui/Shared/Presentation/SelectField.razor index d5bd9cdc..7b269321 100644 --- a/LiftLog.Ui/Shared/Presentation/SelectField.razor +++ b/LiftLog.Ui/Shared/Presentation/SelectField.razor @@ -1,22 +1,21 @@ @inject IJSRuntime JsRuntime -@typeparam T @switch(TextFieldType){ case TextFieldType.Outlined: - + @foreach (var option in Options) { - +
@option.Title
}
break; case TextFieldType.Filled: - + @foreach (var option in Options) { - +
@option.Title
} @@ -29,15 +28,15 @@ @code { - [Parameter] [EditorRequired] public T Value { get; set; } = default!; + [Parameter] [EditorRequired] public string Value { get; set; } = default!; [Parameter] [EditorRequired] public List Options { get; set; } = null!; - [Parameter] [EditorRequired] public EventCallback ValueChanged { get; set; } + [Parameter] [EditorRequired] public EventCallback ValueChanged { get; set; } [Parameter] public TextFieldType TextFieldType { get; set; } = TextFieldType.Outlined; [Parameter(CaptureUnmatchedValues = true)] public Dictionary? AdditionalAttributes { get; set; } - public record SelectOption(string Title, T Value); + public record SelectOption(string Title, string Value); }