question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Complex property validation always happening?

See original GitHub issue

Preempting 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Jun 1, 2017
AssemblyScanner.FindValidatorsInAssemblyContaining<MyValidator>()
.Where(x => x.ValidatorType != typeof(BarValidator))
.ForEach(x => /* register as usual */)
0reactions
jawztherevengecommented, Jun 1, 2017

Oy. Can it be achieved by making the validator implement PropertyValidator and IClientValidatable?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found