dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

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

Open luisabreu opened 1 year ago

luisabreu commented 1 year ago

Is there an existing issue for this?

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

SteveSandersonMS commented 1 year ago

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.

ghost commented 1 year ago

Hi @luisabreu. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

luisabreu commented 1 year ago

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?

SteveSandersonMS commented 1 year ago

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.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

SteveSandersonMS commented 1 year ago

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.

SteveSandersonMS commented 1 year ago

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.

ghost commented 10 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.