Complex property validation always happening?
See original GitHub issuePreempting this issue with the fact that I could be misunderstanding everything. My FluentValidation.Mvc dll is version 6.2.1.
This situation is actually very close to the complex properties example in the docs:
public class Foo {
public string Identifier { get; set; }
public Bar MainBar { get; set; }
public Bar AlternateBarOne { get; set; }
public Bar AlternateBarTwo { get; set; }
}
public class Bar {
public string BarNumber { get; set; }
public BarEnum BarType { get; set; }
}
public class BarValidator : AbstractValidator<Bar> {
public BarValidator() {
RuleFor(x => x.BarNumber).NotEmpty();
}
}
public class FooValidator : AbstractValidator<Foo> {
public FooValidator() {
RuleFor(x => x.MainBar).SetValidator(new BarValidator());
RuleFor(x => x.MainBar.BarNumber)
.Cascade(CascadeMode.StopOnFirstFailure)
.NotEmpty()
.When(y => (!String.IsNullOrEmpty(y.AlternateBarOne.BarNumber)
|| !String.IsNullOrEmpty(y.AlternateBarTwo.BarNumber))).WithMessage("Bar required before
alternate bars.");
// etc
}
}
The problem is that the BarValidator
happens for all of the Bar
properties. In fact, even if I take out the rule for MainBar
and don’t use the BarValidator
at all, they’re still fired.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Client side validation not working with reused and nested ...
I have an asp.net MVC 5 application in which I tried to re-use a nested complex view model class in different places in...
Read more >Fixing Vuetify's Form Validation. Quite ... - Robert Mirabelle
Quite unfortunately, Vuetify form validation effectively arrives “broken” out of the box. Here, I'll explain the problem and suggest a solution.
Read more >15.2 Understanding Validations
Validation error messages display when the validation fails the equality test, or evaluates to FALSE, or a non-empty text string is returned. Validation,...
Read more >Input Validation - Enforcing Complex Business Data Rules ...
When validation takes place is specified by the UpdateSourceTrigger property of the Binding, which is set to PropertyChanged for most properties. Some ...
Read more >Input Validation vs. Model Validation in ASP.NET MVC
What this means is that we will always run all validators on an object, if that object had at least one value bound...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oy. Can it be achieved by making the validator implement
PropertyValidator
andIClientValidatable
?