I was looking at using Transform but it looks like it will be removed soon and a new way with computed properties is to be used.
https://github.com/FluentValidation/FluentValidation/issues/2072
My question is how do I use this new way when using blazor and the plugins for hooking up the front end like: https://github.com/Blazored/FluentValidation
// After migration - the transformation takes place inside the model and is exposed via a computed property.
class Foo
{
public string SomeValue { get; set; }
public int? SomeValueAsInt => int.TryParse(SomeValue, out int val) ? val : null;
}
public class FooValidator : AbstractValidator<Foo>
{
public FooValidator()
{
RuleFor(x => x.SomeValueAsInt).NotNull().GreaterThan(5);
}
}
I tried to do this but now my validation on the front end does not work (if I type something in a box it won’t trigger).
I think it is because I am hooking up the control to SomeValue and the RuleFor is for SomeValueAsInt so the rule never gets triggered as it’s not for SomeValue (I am using havit)
<HxInputText @bind-Value="SomeValue " Label="Name" />
When I use the old transform way that is being removed it would work but of course I won’t use it as it will be removed soon.
How should I be doing this?
1