I have an editform using an editcontext:
<EditForm OnValidSubmit="HandleValidSubmit" EditContext="_editContext" Context="auth"><DataAnnotationsValidator /><input type="time" @bind-value="_foodTruck.EndDelivery" @onkeydown="@(q=>ResetValidation("EndDelivery"))"><ValidationMessage For="() => _foodTruck.EndDelivery" /><input type="time" @bind-value="_foodTruck.StartDelivery" @onkeydown="@(q=>ResetValidation("StartDelivery"))"><ValidationMessage For="() => _foodTruck.StartDelivery" /><input class="btn btn-default" type="submit" value="save" /></EditForm>I do some custom validations in HandleValidSubmit:
EditContext _editContext = new EditContext(_foodTruck);private async void HandleValidSubmit(){ var messageStore = new ValidationMessageStore(_editContext); if (_foodTruck.StartDelivery >= _foodTruck.EndDelivery) { messageStore.Add(_editContext.Field("EndDelivery"), "Bad time entered"); _editContext.NotifyValidationStateChanged(); } if (!_editContext.Validate()) return;}What now happens is that my custom error ("bad time entered") is displayed at the right position. The only issue is: That error does not disappear when I change the value. So HandleValidSubmit is never called again if I click onto the submit button.
I also tried emptying the validationerrors when modifying the fields:
protected void ResetValidation(string field) { var messageStore = new ValidationMessageStore(_editContext); messageStore.Clear(_editContext.Field(field)); messageStore.Clear(); _editContext.NotifyValidationStateChanged(); }This is called by onkeydown. But that doesn't seem to have an effect, either. The Errormessage does not disappear and so HandleValidSubmit isn't called either.