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: Add method to submit form async #10953

Open FluentGuru opened 5 years ago

FluentGuru commented 5 years ago

Right now you can only submit the EditForm by adding a button[type=submit] and clicking it. I'd like to have a way to manually invoke the form submit with a method. Something like

`

`

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @FluentGuru.

@SteveSandersonMS I think this is a reasonable ask and quite common use case. What do you think?

FluentGuru commented 5 years ago

@mkArtakMSFT I made a workaround to have this functionality while it's being implemented https://gist.github.com/FluentGuru/1d7c6af745906871332a9ac4dd14954c This extension method takes the implementation inside EditForm.cs https://github.com/aspnet/AspNetCore/blob/67b665208c94908ef8503e39d54e078a2ea778dc/src/Components/Components/src/Forms/EditForm.cs#L120

I might make a PR to properly implement this on the API after I solve my immediate problem if you guys accept it :D

FluentGuru commented 5 years ago

I created a PR with this change :)

mkArtakMSFT commented 5 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

mkArtakMSFT commented 5 years ago

Thanks for your effort, @FluentGuru. We will however look into this issue in a more broader way in the future release, as we're handling only highest-priority issues in this area for the upcoming release.

FluentGuru commented 5 years ago

Alright. Thanks for the heads up :)

loganmarshall1 commented 4 years ago

Fantastic idea!!

mkArtakMSFT commented 10 months ago

@SteveSandersonMS any thoughts about this one?

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.

bendrick92 commented 7 months ago

Bumping in 2024 - would love to see this available. My use case is:

  1. Trigger a form submit
  2. Validate
  3. If invalid, apply a temporary style to the form (i.e. shake the button/show a message)
  4. Await a delay of x seconds
  5. Toggle the style off
SteveSandersonMS commented 7 months ago

@bendrick92 As far as I know, your goals can already be satisfied. Inside any @onsubmit handler, you can modify a flag that control the form's styles, and then use an await Task.Delay(...) to wait for x seconds, then turn off the flag.

bendrick92 commented 7 months ago

@bendrick92 As far as I know, your goals can already be satisfied. Inside any @onsubmit handler, you can modify a flag that control the form's styles, and then use an await Task.Delay(...) to wait for x seconds, then turn off the flag.

Yes, I just discovered this seems to be working!

OnSubmit='@(() => HandleSubmit())'
private async Task HandleSubmit()
...
ShowValidationWarnings = true;
await Task.Delay(1000);
ShowValidationWarnings = false;

Thanks for the reply @SteveSandersonMS!