Skip to content

EditForm: change API to allow form subission from code #48613

Description

@luisabreu

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Currentyle, it seems there's no way to submit an EditForm programatically from C# code because the HandleSubmitAsync method is private.

Describe the solution you'd like

Adding a public method that submits the form would allows us to have forms without submit buttons (ex.: scenario where the user must pick items from lists and where picking an item should submit a form) and would allow us to reuse the context+validation logic currently implemented by the EditForm.

Additional context

No response

Activity

  1. ghost added
    needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
    on Jun 5, 2023
  2. added
    area-blazorIncludes: Blazor, Razor Components
    and removed
    needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
    on Jun 5, 2023
  3. SteveSandersonMS commented on Jun 5, 2023

    @SteveSandersonMS
    Member

    To clarify, did you try triggering your own submit handler directly? That is, whatever method is wired up to the form - could you just call it manually? If your goal is to run validation, you can also run yourEditForm.EditContext.Validate() directly.

    I'm asking to clarify whether there is some particular thing that can't be achieved this way, or whether it's just that you're looking for a more convenient built-in mechanism.

  4. added
    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.
    on Jun 5, 2023
  5. luisabreu commented on Jun 5, 2023

    @luisabreu
    Author

    Yes, we're doing as you suggested: calling the validate and then calling the handler but it kind of breaks the flow, no? why can't we have a public submit method on the EditForm?

  6. ghost added
    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.
    on Jun 5, 2023
  7. ghost removed
    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.
    on Jun 5, 2023
  8. SteveSandersonMS commented on Jun 6, 2023

    @SteveSandersonMS
    Member

    Sure, that's a totally reasonable request. I was only asking to clarify if an alternative existed and to make sure I wasn't missing something about what exactly you would expect the submit method to do.

  9. removed
    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.
    on Jun 6, 2023
  10. added this to the Backlog milestone on Jun 6, 2023
  11. SteveSandersonMS commented on Jun 6, 2023

    @SteveSandersonMS
    Member

    I've moved this to backlog because we already have a full work schedule for .NET 8. However if you are keen enough to implement this and do a PR (including E2E tests) we would certainly consider taking it.

  12. SteveSandersonMS commented on Jun 6, 2023

    @SteveSandersonMS
    Member

    Just to add: this should probably work by making a JS interop call to instruct the browser to submit the form (instead of just invoking the .NET handler). That way any other expected client-side behaviors, such as triggering HTML's built-in validation prompts, should also occur.

  13. removed
    pending-ci-rerunWhen assigned to a PR indicates that the CI checks should be rerun
    on Feb 6, 2024
  14. removed
    pending-ci-rerunWhen assigned to a PR indicates that the CI checks should be rerun
    on Feb 13, 2024
  15. added
    help wantedUp for grabs. We would accept a PR to help resolve this issue
    and removed on Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentscopilot-candidatehelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions