Skip to content
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

[Bug] SetValidator appears to take no effect #213

Open
pingu2k4 opened this issue Feb 20, 2024 · 0 comments
Open

[Bug] SetValidator appears to take no effect #213

pingu2k4 opened this issue Feb 20, 2024 · 0 comments
Labels
Bug Something isn't working Triage Issue needs to be triaged

Comments

@pingu2k4
Copy link

Describe the bug
When using SetValidator on a list of items, it appears to not be used. Whereas replicating the same rules within ChildRules does work.

To Reproduce
Steps to reproduce the behavior:

  1. Create an object with a list of T
  2. Create a validator for T, which a rule you can easily attempt to break
  3. Create a form using the object with a list of T, and hook up the validation as well as the ability to create items and "break" the rule
  4. attempt to submit and notice that validation passes, and OnValidSubmit triggers
  5. Recreate the same rules within ChildRules
  6. Try again and notice that OnValidSubmit does not trigger.

Expected behavior
Identical rules within ChildRules and SetValidator should behave identically

Screenshots
If applicable, add screenshots to help explain your problem.

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor WebAssembly

Additional context
I am using the following rules. The ModifyEmployeeModelRoleValidator has rules identical to those inside ChildRules. If I comment out the ChildRules part, then validation succeeds, incorrectly.

RuleForEach(x => x.Roles).SetValidator(new ModifyEmployeeModelRoleValidator());
RuleForEach(x => x.Roles).ChildRules(role =>
{
    role.RuleFor(x => x.Level).GreaterThanOrEqualTo(x => x.MinLevel)
        .When(x => x.MinLevel is not null, ApplyConditionTo.CurrentValidator)
        .LessThanOrEqualTo(x => x.MaxLevel - 1)
        .When(x => x.MaxLevel is not null, ApplyConditionTo.CurrentValidator);
});
@pingu2k4 pingu2k4 added Bug Something isn't working Triage Issue needs to be triaged labels Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant