5

Is there any way to clear the error for a specific field when using using Blazor validation ?

I tried something like the following, but it does not clear the error message :

MyEditContext.MarkAsUnmodified(MyEditContext.Field("Filename"));
2
  • Share the full code to understand better. Are you storing messages in ValidationMessageStore ? Commented Nov 16, 2019 at 11:39
  • There's a chance you just have to call StateHasChanged() Commented Nov 17, 2019 at 21:00

2 Answers 2

6

In case anyone else is looking for the same thing, you can do the following and it will clear the existing error message for a particular field :

MyEditContext.NotifyFieldChanged(MyEditContext.Field("MyFieldName"));
Sign up to request clarification or add additional context in comments.

1 Comment

This is not going to clear the error message on the field, it will reevaluate the field, if the error persist the message will continue to be visible.
0

maybe someone else will need it.

For clear all error create new EditContext:

1)Dont't use in form: EditForm Model="@LoginModel"

2)Use: EditForm EditContext="editContext"

3)For clear all error create new EditContext:

protected void CreateNewLoginModel()
{
    LoginModel = new();
    editContext = new EditContext(LoginModel);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.