Comments (13)
Thanks for the PR!
Sorry for the delay! I'm fixing this now along with the other issue. Gonna run some tests to make sure they work properly before publishing.
from fluentvalidation.blazor.
Sure, I don't mind adding support for FluentValidation 9.
(It will be a breaking changes though. Ideally it ships with .NET 5 but I don't mind doing it sooner)
I'm curious though, what makes you must use FluentValidation 9?
from fluentvalidation.blazor.
At the moment it's not necessarily a must, more that I just bumped into it when I installed the FluidValidation pack into another project which my blazor WebAssembly project had as dependency. Took a bit to figure out what was wrong exactly, just wanted it to bring it to your attention before other people came across it as well 👍
from fluentvalidation.blazor.
Just ran into this issue myself. I just updated cause it was available, and then I got the same error as above.
Rolling back FluentValidation.AspNetCore to 8.6.2 fixes the issue
from fluentvalidation.blazor.
This one bit me too. I was working on a POC and just installed the latest FluentValidation package (9.0.1) not knowing that v9 was just released. I kept getting the same error as Hans and was beating my head against the wall trying to figure out what was going on. Reverted to 8.6.2 and everything is grand now. Thank you @HansKlokkenspel for info.
from fluentvalidation.blazor.
I ended up on this issue with the same issue 😅 . I'm happy to clone & reference the source directly, but as @ryanelian mentioned, there are some breaking changes.
Specifically, this method doesn't compile anymore:
private ValidationResult TryValidateModel(EditContext editContext)
{
try
{
return Validator.Validate(editContext.Model); // <-- Validator.Validate now accepts an IValidationContext, but editContext.Model is of type object
}
...
}
I'm gonna try and cast it to IValidationContext
and see what gives.
from fluentvalidation.blazor.
Yeah that didn't work 😁
from fluentvalidation.blazor.
Ah, but this does work: return Validator.Validate(new ValidationContext<object>(editContext.Model));
I'm not sure if there are any potential issues with doing ValidationContext<object>
, but I'm gonna try and use reflection to instantiate a generically typed instance (so that the T
in ValidationContext<T>
is actually the type of the model).
from fluentvalidation.blazor.
I came up with this method to instantiate a ValidationContext<T>
:
private IValidationContext CreateValidationContext(object model, PropertyChain propertyChain = default, IValidatorSelector validatorSelector = default)
{
var contextType = typeof(ValidationContext<>);
var modelType = model.GetType();
var closedContextType = contextType.MakeGenericType(modelType);
return (IValidationContext)Activator.CreateInstance(
closedContextType,
model,
propertyChain ?? new PropertyChain(),
validatorSelector ?? ValidatorOptions.Global.ValidatorSelectors.DefaultValidatorSelectorFactory());
}
But it fails in the browser with:
Cannot validate instances of type 'RuntimeType'. This validator can only validate instances of type 'MyModel'
I'll go with my former solution instead. I'll also send a PR with updated package references and code changes to accommodate the breaking changes of FluentValidations 9.
from fluentvalidation.blazor.
Ahhh wait, I made a mistake. It DOES work 😅 I was passing in the model TYPE, not the model itself 🤦😁
from fluentvalidation.blazor.
I created a PR here.
from fluentvalidation.blazor.
https://www.nuget.org/packages/Accelist.FluentValidation.Blazor/3.0.0
Uploaded package to nuget, wait for it to be indexed.
This version passes basic visual tests on both server-side and client-side Blazor, but as usual with breaking changes please test your codes for unexpected bugs.
from fluentvalidation.blazor.
Great stuff. Thanks for this release @ryanelian !
from fluentvalidation.blazor.
Related Issues (20)
- InputSelect not clearing message HOT 2
- OnFieldChanged not trigger HOT 1
- Consider using tags to version releases and use Github "releases" tab HOT 4
- How to do async validation HOT 6
- Library is not compatible with Client-Side Blazor due to Exception with async validation HOT 7
- International Date format yyyy-MM-dd error HOT 4
- Minor FluentValidation integration improvements HOT 1
- Validation messages are link to the first child object when using a list in the Model of the edit context HOT 5
- Silent errors misleading HOT 3
- Validation Message is not working for items inside a list HOT 1
- Nested objects are only validated when submitting the form HOT 2
- EditForm OnValidSubmit event is raised when validation failed using MustAsync() method. HOT 3
- How to trigger the validate method manually HOT 2
- Blazor WASM Project With Both Client & Server Validation HOT 1
- Async validation to server-side call HOT 2
- Suitable for Blazor webassembly? HOT 2
- Upgraded to FluentValidation 10.x and .NET 6 Preview 3, getting the following error HOT 5
- Is this repo abandoned? HOT 2
- Async dispose results in null reference.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentvalidation.blazor.