Blazored / FluentValidation

A library for using FluentValidation with Blazor
https://blazored.github.io/FluentValidation/
MIT License
597 stars 85 forks source link

[Bug] ValidationMessageStore is not accessible #197

Closed czuvich closed 1 year ago

czuvich commented 1 year ago

Describe the bug I cannot reference the ValidationMessageStore for the EditContext in order to clear the messages using this validator.

To Reproduce Steps to reproduce the behavior:

  1. Create a blank page with a FluentValidator, ValidationMessageStore, and EditContext.
  2. Trigger an invalid state on Submit.
  3. The ValidationMessageStore referenced in the razor page is always empty.

Expected behavior The ValidationMessageStore should have the validation messages in it.

Additional context It looks like the extensions create a local instance of ValidationMessageStore. Do you have an approach that could reference the ValidationMessageStore in the page consumed by the context? I've included MS guidance on this below.

In the following component, the HandleValidationRequested handler method clears any existing validation messages by calling ValidationMessageStore.Clear before validating the form.).

https://learn.microsoft.com/en-us/aspnet/core/blazor/forms-and-input-components?view=aspnetcore-7.0

Sharaf-Mansour commented 1 year ago

@czuvich Take a look at #168

czuvich commented 1 year ago

Thanks @Sharaf-Mansour! EditForm is such a mess in Blazor. I ended up modifying the FluentValidationValidator by adding a public ValidationMessageStore property and using that in the EditContextFluentValidationExtensions methods.