0

I have a form:

<EditForm Model="@Model" OnValidSubmit="@SubmitSuccess" OnInvalidSubmit="@SubmitFailure" Context="editContext">
    <DataAnnotationsValidator/> 
    //Here the controls
</EditForm>

In this particular form I have a required property but this property is set in code and not from an input control in the form.

I have a property:

private EditContext editContext;

And in OnParamatersSet() I do:

editContext = new EditContext(Model);

I have custom data annotations for validation and they are displayed correctly. I'm trying to clear the validation messages in code and I have tried:

Recreating the edit context:

editContext = new EditContext(Model);
await InvokeAsync(StateHasChanged);

and

Notify the property changed:

editContext.NotifyFieldChanged("Property");
await InvokeAsync(StateHasChanged);

But both are not working.

So how can I successfully clear the validation messages?

Ivan Debono
  • 457
  • 3
  • 14
  • Does this answer your question? [How to reset custom validation errors when using editform in blazor razor page](https://stackoverflow.com/questions/60917323/how-to-reset-custom-validation-errors-when-using-editform-in-blazor-razor-page) – Eddi Jul 05 '23 at 09:32
  • Tried all the solutions there. Nothing is working. – Ivan Debono Jul 05 '23 at 10:17
  • Only objects that write messages to the Validation Store can clear them. There's no generic "clear all messages". So if you have "custom data annotations for validation" then you need methods within those objects to reset the messages they log into the message store. – MrC aka Shaun Curtis Jul 05 '23 at 10:45

0 Answers0