question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to clear the Editform validation messages with a button click in Blazor

See original GitHub issue

Describe the bug

Need to clear the EditForm ValidationMessages with a button click

To Reproduce

Check the below sample code blocks

<EditForm Model="@exampleModel" OnValidSubmit="HandleValidSubmit"> <DataAnnotationsValidator /> <ValidationSummary />

`<InputText id="name" @bind-Value="exampleModel.Name" />`

<button type="submit">Submit</button> </EditForm>

<button @onclick="clicked"></button>

@code { void clicked() { // Reset the validation messages here }

}

Further technical details

Need to reset the validation error message with a button click action. Any idea of how to reset the status ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
guardrexcommented, Aug 18, 2020

The updates to the topic are LIVE!

https://docs.microsoft.com/aspnet/core/blazor/forms-validation

The new content includes the use of validator components to manage validation message stores, business logic validation, and server-side validation. The server-side section includes data annotations validation and custom logic in a server API. We’ll react to feedback on the new coverage as it comes in.

Thanks @RemiBou 🎷 for your help and contributions to the topic.

1reaction
Zoxivecommented, Feb 13, 2021

I have a dynamic form, where i can add/remove fields which are displayed.

If i have an validation messages for a field, and then the field is removed from the page (the input component is disposed) the validation messages stay. I feel like the Dispose() https://github.com/dotnet/aspnetcore/blob/231db98e76787b120d2a13fda53b8623f7137b01/src/Components/Web/src/Forms/InputBase.cs#L316 on InputBase should call _parsingValidationMessages.Clear()

This prevents my submit from working since the EditContext thinks my form has validations… well it did but I removed the field…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset custom validation errors when using editform ...
I solved this by creating a new EditContext on Validation-reset. So I simply added the following line to the ResetValidation-Method:
Read more >
Resetting A TelerikForm in Blazor back to Pristine State
Creating a new EditContext should clear the validation message store as well. You can find an example of this in our documentation: https://docs ......
Read more >
A Blazor Validation Control
When the user clicks on the Submit button, EditForm either: ... form level validation // Form level - clear all validation messages //...
Read more >
ASP.NET Core Blazor forms and input components
The EditContext tracks metadata about the edit process, including which form fields have been modified and the current validation messages.
Read more >
context.Validate() and CustomValidator - Microsoft Q&A
Since I use this condition in button : <button type="submit" ... it will trigger this event, and the message store will clear.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found