How to clear the Editform validation messages with a button click in Blazor
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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 onInputBase
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…