|
5 | 5 |
|
6 | 6 | <MudDialogEx> |
7 | 7 | <DialogContent> |
8 | | - @if (Value is not null && editContext is not null) |
| 8 | + @if (Value is not null) |
9 | 9 | { |
10 | | - <EditForm EditContext="@editContext"> |
| 10 | + <EditForm @ref="editFormRef" Model="@Value"> |
11 | 11 | <DataAnnotationsValidator /> |
12 | 12 | @FormContent(Value) |
13 | 13 | </EditForm> |
|
27 | 27 | @CustomDialogActions |
28 | 28 | } |
29 | 29 | <MudButton OnClick="OnCancelAsync_Internal" Variant="Variant.Outlined" Class="ml-4">@CancelButtonText</MudButton> |
30 | | - @if (Value is not null && editContext is not null) |
| 30 | + @if (Value is not null) |
31 | 31 | { |
32 | 32 | <MudButton Color="Color.Primary" OnClick="OnSubmitAsync_Internal" Variant="Variant.Filled" Disabled="@SubmitButtonDisabled" Class="ml-4">@SubmitButtonText</MudButton> |
33 | 33 | } |
|
66 | 66 | [Parameter] |
67 | 67 | public string CancelButtonText { get; set; } = "Cancel"; |
68 | 68 |
|
69 | | - private EditContext? editContext; |
| 69 | + private EditForm? editFormRef; |
70 | 70 |
|
71 | 71 | private bool hasError; |
72 | 72 | private string? errorMessage; |
73 | 73 |
|
74 | 74 | public bool Validate() |
75 | 75 | { |
76 | | - ArgumentNullException.ThrowIfNull(editContext); |
| 76 | + ArgumentNullException.ThrowIfNull(editFormRef); |
| 77 | + ArgumentNullException.ThrowIfNull(editFormRef.EditContext); |
77 | 78 |
|
78 | | - return editContext.Validate(); |
| 79 | + return editFormRef.EditContext.Validate(); |
79 | 80 | } |
80 | 81 |
|
81 | 82 | protected override async Task OnInitializedAsync() |
|
93 | 94 | errorMessage = args.ErrorMessage; |
94 | 95 | } |
95 | 96 |
|
96 | | - // todo check how this behaves when a parameter is updated!!! |
97 | | - protected override void OnParametersSet() |
98 | | - { |
99 | | - if (Value is null) |
100 | | - return; |
101 | | - |
102 | | - editContext = new EditContext(Value); |
103 | | - } |
104 | | - |
105 | 97 | private async Task OnSubmitAsync_Internal() |
106 | 98 | { |
107 | 99 | ArgumentNullException.ThrowIfNull(Value); |
108 | | - ArgumentNullException.ThrowIfNull(editContext); |
| 100 | + ArgumentNullException.ThrowIfNull(editFormRef); |
| 101 | + ArgumentNullException.ThrowIfNull(editFormRef.EditContext); |
109 | 102 |
|
110 | | - EditFormSubmitArgs<TValue, TReturnValue> args = new(Value, editContext); |
| 103 | + EditFormSubmitArgs<TValue, TReturnValue> args = new(Value, editFormRef.EditContext); |
111 | 104 |
|
112 | 105 | if (OnSubmit.HasDelegate) |
113 | 106 | await OnSubmit.InvokeAsync(args); |
|
0 commit comments