Skip to content

Commit 6b9bef5

Browse files
Put back the earlier EditForm behavior of using an empty-string handler name for now
1 parent 995f172 commit 6b9bef5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ internal partial class EndpointHtmlRenderer
1414

1515
internal Task DispatchSubmitEventAsync(string? handlerName)
1616
{
17-
if (string.IsNullOrEmpty(handlerName))
17+
if (handlerName is null)
1818
{
1919
// Currently this also happens if you forget to add the hidden field, but soon we'll do that automatically, so the
2020
// message is designed around that.
21-
throw new InvalidOperationException($"Cannot dispatch the POST request to the Razor Component endpoint, because the POST data does not specify which form is being submitted. To fix this, ensure form elements have an @onsubmit:name attribute with any unique value, or pass a Name parameter if using EditForm.");
21+
throw new InvalidOperationException($"Cannot dispatch the POST request to the Razor Component endpoint, because the POST data does not specify which form is being submitted. To fix this, ensure form elements have an @onsubmit:name attribute with any unique value, or pass a FormHandlerName parameter if using EditForm.");
2222
}
2323

2424
if (!_namedSubmitEventsByAssignedName.TryGetValue(handlerName, out var frameLocation))
2525
{
2626
// This might only be possible if you deploy an app update and someone tries to submit
2727
// an old version of a form, and your new app no longer has a matching name
28-
throw new InvalidOperationException($"Cannot submit the form '{handlerName}' because no submit handler was found with that name. Ensure forms have a unique @onsubmit:name attribute, or pass the Name parameter if using EditForm.");
28+
throw new InvalidOperationException($"Cannot submit the form '{handlerName}' because no submit handler was found with that name. Ensure forms have a unique @onsubmit:name attribute, or pass the FormHandlerName parameter if using EditForm.");
2929
}
3030

3131
var eventHandlerId = FindEventHandlerIdForNamedEvent("onsubmit", frameLocation.ComponentId, frameLocation.FrameIndex);

src/Components/Web/src/Forms/EditForm.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,20 @@ void RenderFormContents(RenderTreeBuilder builder, FormMappingContext? bindingCo
172172

173173
builder.AddMultipleAttributes(4, AdditionalAttributes);
174174
builder.AddAttribute(5, "onsubmit", _handleSubmitDelegate);
175-
builder.OpenComponent<CascadingValue<EditContext>>(6);
176-
builder.AddComponentParameter(7, "IsFixed", true);
177-
builder.AddComponentParameter(8, "Value", _editContext);
175+
if (bindingContext != null)
176+
{
177+
builder.AddNamedEvent(6, "onsubmit", bindingContext.Name);
178+
}
179+
builder.OpenComponent<CascadingValue<EditContext>>(7);
180+
builder.AddComponentParameter(8, "IsFixed", true);
181+
builder.AddComponentParameter(9, "Value", _editContext);
178182
if (bindingContext != null && !OperatingSystem.IsBrowser())
179183
{
180-
builder.AddComponentParameter(9, "ChildContent", _renderWithBindingValidator);
184+
builder.AddComponentParameter(10, "ChildContent", _renderWithBindingValidator);
181185
}
182186
else
183187
{
184-
builder.AddComponentParameter(10, "ChildContent", ChildContent?.Invoke(_editContext));
188+
builder.AddComponentParameter(11, "ChildContent", ChildContent?.Invoke(_editContext));
185189
}
186190
builder.CloseComponent();
187191
builder.CloseElement();

0 commit comments

Comments
 (0)