Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor] OnValidSubmit not invoked when submit button clicked #12919

Closed
brianlagunas opened this issue Aug 6, 2019 · 3 comments
Closed

[Blazor] OnValidSubmit not invoked when submit button clicked #12919

brianlagunas opened this issue Aug 6, 2019 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@brianlagunas
Copy link

brianlagunas commented Aug 6, 2019

Describe the bug

When the ValidationSummary is define at the top of the EditForm, and you have existing errors in the form, if you fix the error and then immediately click the submit button, the errors are fixed however the submit button does not invoke OnValidSubmit.

If you define the ValidationSummary at the end of the EditForm and perform the same task, it will work as expected.

This doesn't work

<EditForm Model="@person" OnInvalidSubmit="@HandleInvalidSubmit" OnValidSubmit="@HandleValidSubmit">

    <DataAnnotationsValidator />
    <ValidationSummary />

    <InputText @bind-Value="person.Name"></InputText>
    <InputNumber @bind-Value="person.Age"></InputNumber>
    <button type="submit">Submit</button>
</EditForm>

This works:

<EditForm Model="@person" OnInvalidSubmit="@HandleInvalidSubmit" OnValidSubmit="@HandleValidSubmit">

    <DataAnnotationsValidator />

    <InputText @bind-Value="person.Name"></InputText>
    <InputNumber @bind-Value="person.Age"></InputNumber>
    <button type="submit">Submit</button>

    <ValidationSummary />
</EditForm>

I believe this is occurring because when you click the submit button, focus is lost from the inputs which causes the errors to be fixed, however the submit button is not actually clicked. Therefore the OnValidSubmit event is not fired.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 3.0.100-preview7-012821
  2. Run this code (see above snippets)

Expected behavior

When the ValidationSummary is defined at the top of the EditForm, and an error is fixed. I should should be able to click the submit button and have the OnValidSubmit event invoked

Screenshots

Video of bug: https://clips.twitch.tv/AuspiciousDepressedSproutPeteZarollTie

Video of workaround: https://www.twitch.tv/videos/463432083

@brianlagunas brianlagunas changed the title OnValidSubmit not invoked when submit button clicked [Blazor] OnValidSubmit not invoked when submit button clicked Aug 6, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Aug 6, 2019
@brianlagunas
Copy link
Author

Added videos clips of the twitch stream which demonstrates the issue.

@campersau
Copy link
Contributor

From the video it looks like the button is not clicked the first time because the content jumps up because the validation message is removed. I would suggest adding some CSS so the content does not jump or try use the keyboard navigation e.g. tab -> enter then it should work the first time.

@brianlagunas
Copy link
Author

@campersau That was exactly it! Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants