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.

Disable auto-validation

See original GitHub issue

FV works just like ASP.NET’s own validation - before an action is executed, it automatically validates the arguments, and populates the ModelState. So in the action you can check ModelState.IsValid and everything “just works”.

Is it possible to disable this auto-validation, and only run it on demand?

We use a CQRS pipeline (using MediatR), which performs validation. A typical validator and action:

// the validator
public class CommandValidator : AbstractValidator<Command> { ... }

// the action
public IActionResult Edit(Command command)
{
    // note there is no check for ModelState.IsValid
    _mediator.Send(command);
    return View();
}

So, FV performs auto-validation for that action, and the CQRS pipeline thereafter also performs validation - so the input is validated twice, and the UI shows two validation errors for every invalid property.

Is it possible to configure FV to only validate on demand, and not automatically before every action?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
julianpaulozzicommented, Jun 9, 2017

It’s nice to have automatic validation for everything in simple configuration entry. But can not ignore some edge cases with an attribute or interface for example?

1reaction
JeremySkinnercommented, Feb 21, 2017

That’s handled by the FluentValidationClientModelValidatorProvider, which is all set up through the AddFluentValidation() method. If you’re not using the automatic integration, you’ll need to register all that manually (and also create your own ViewOptionsSetup class to plug it into MVC). I’d suggest looking through the code of the FluentValidationMvcExtensions class (https://github.com/JeremySkinner/FluentValidation/blob/master/src/FluentValidation.AspNetCore/FluentValidationMvcExtensions.cs), particularly lines 61-67 and 120-127. That should give you everything you need.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable validation of HTML form elements
If you want to disable client side validation for a form in HTML, add the novalidate attribute to the form element. Ex:
Read more >
validate plugin. How to disable auto validation on keypress ...
I wish to be able to disable the automatic validation for one field/element only after submission how can this be done? I have...
Read more >
How to disable validation of form's child controls
To achieve this behavior, you can either set the CausesValidation property to false for all child controls or the parent form's AutoValidate ......
Read more >
AutoValidate Enum (System.Windows.Forms)
Disable, 0. Implicit validation will not occur. Setting this value will not interfere with explicit calls to Validate() or ValidateChildren().
Read more >
autovalidateMode property - Form class - widgets library
Used to enable/disable form fields auto validation and update their error text. If AutovalidateMode.onUserInteraction, this FormField will only ...
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