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

[Question] Silently validate model / TryValidate() #236

Open
Lorenz5600 opened this issue Nov 11, 2024 · 1 comment
Open

[Question] Silently validate model / TryValidate() #236

Lorenz5600 opened this issue Nov 11, 2024 · 1 comment
Labels
Question Question about this project Triage Issue needs to be triaged

Comments

@Lorenz5600
Copy link

Hi,

I'm looking for a way to silently validate an EditContext when using FluentValidation, i.e. Validate without generating ValidationMessages. This feature is quite useful, e.g. to disable/enable a submit button.

When using DataAnnotationsValidator this is possible by calling Validator.TryValidateObject() like:

bool FormIsValid()
{
    var validationResults = new List<ValidationResult>();
    var validationContext = new ValidationContext(EditContext.Model);
    Validator.TryValidateObject(EditContext.Model, validationContext, validationResults, true);
    return !validationResults.Any();
}

Unfortunately I don't fully understand the way FluentValidation is hooked up into EditContext, but perhaps someone had an idea or already implemented something similiar and can get me on the right track.

Thanks in advance

Jake

@Lorenz5600 Lorenz5600 added Question Question about this project Triage Issue needs to be triaged labels Nov 11, 2024
@Lorenz5600
Copy link
Author

Took a walk and revisited the code...voilá, guess I figured it out! Perhaps not the best possible solution (comments welcome!), but it's a start:

WIP repo

Cheers,
Jake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Question about this project Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant