Skip to content

feat: Add EditForm.SubmitAsync for programmatic form submission - #67551

Open
JayArrowz wants to merge 14 commits into
dotnet:mainfrom
JayArrowz:48613-blazor-allow-pragmatic-form-submission
Open

JayArrowz wants to merge 14 commits into
dotnet:mainfrom
JayArrowz:48613-blazor-allow-pragmatic-form-submission

Conversation

@JayArrowz

@JayArrowz JayArrowz commented Jul 1, 2026 •

Copy link
Copy Markdown

Add EditForm.SubmitAsync for programmatic form submission

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

Currently there is no way to submit an EditForm programmatically from C# code, because HandleSubmitAsync is private. This forces developers to manually call EditContext.Validate() and then invoke their submit handler separately, which breaks the form's submission flow and bypasses any client-side validation prompts.

This PR adds a public SubmitAsync method to EditForm that submits the form from code, triggering the same validation and submission lifecycle as if the user had clicked a submit button.

As suggested by @SteveSandersonMS #48613 (comment), this works by making a JS interop call to instruct the browser to submit the form via HTMLFormElement.requestSubmit(). This ensures that any expected client-side behaviors, such as triggering HTML's built-in validation prompts, also occur.

Interactive rendering: The resulting submit event is handled by the form's onsubmit handler, which runs the EditContext validation and invokes the appropriate OnSubmit, OnValidSubmit, or OnInvalidSubmit callback.

Server-side rendering (SSR): Not applicable. SubmitAsync relies on JS interop, which requires an interactive rendering mode. In pure SSR scenarios there is no JS interop available to call this method, use a regular instead.

Usage:

<EditForm Model="@model" OnValidSubmit="@HandleValidSubmit" @ref="_editForm">
    <DataAnnotationsValidator />
    <InputText @bind-Value="model.Name" />
</EditForm>

<button @onclick="SubmitFromCode">Submit</button>

@code {
    private EditForm _editForm = null!;

    private async Task SubmitFromCode()
        => await _editForm.SubmitAsync();
}

Fixes #48613

@JayArrowz

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@JayArrowz
JayArrowz marked this pull request as ready for review July 2, 2026 18:17
@JayArrowz
JayArrowz requested a review from a team as a code owner July 2, 2026 18:17
@Youssef1313 Youssef1313 added the area-blazor Includes: Blazor, Razor Components label Sep 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EditForm: change API to allow form subission from code

2 participants