-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow adding failures programmatically #243
Comments
Upvote :) |
You can add it to the EditContext messagestore, but you have to create a FieldIdentifier from the backend. It's a bit hacky when you get to an error in a collection. Cause then the backend would return something like "Key: Model.People[2].Name" which doesn't directly work as a fieldidentifier. If it's a simple property (not collection), you can do something like this
|
This repo already has the ability to translate paths to field identifiers: FluentValidation/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs Line 181 in 8afbf82
And it already uses that to copy the fluent validation results into the message store: FluentValidation/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs Lines 52 to 55 in 8afbf82
So a method for manually adding backend errors could have a friendlier parameter type that doesn't involve |
Yes that's exactly what I'd like. But when I try to add paths with collections to the errors, it doesn't correctly connect to the correct field. If I do it with a simple property such as "Name", then Perhaps you have another way of doing this? |
FluentValidationValidator does not allow adding failures to the failure collection. This is needed in the following scenario:
Scenario
Client is a Blazor web assembly app. Server is an API project. Both perform validations using fluent validation. Thus, an API request from the client might get a response containing a
List<ValidationFailure>
. If it were possible to add these (backend) failures to the current collection, the UI would be updated accordingly (e.g. coloring the related fields in red).Proposed solution
A new method
** Alternatives considered**
I considered extending the class
FluentValidationValidator
in my project. HoweverLastValidationResult
(the dictionary of failures) is an internal field, which prevents accessing it from external projects.An alternative solution would be to make this field protected, making it possible to manipulate this collection in derived classes.
The text was updated successfully, but these errors were encountered: