SiberianGuy
SiberianGuy

Reputation: 25312

FluentValidation client-side validation

I tried to use GreaterThen validator and it looks like it doesn't support client-side validation. Is there a list of FluentValidation validators which support client-side validation?

Upvotes: 15

Views: 9047

Answers (3)

Sinan Bozkuş
Sinan Bozkuş

Reputation: 441

You can use Form Helper. It adds client-side support to Fluent-Validation.

Startup.cs

services.AddFormHelper();
With configuration: (optional)

services.AddFormHelper(new FormHelperConfiguration
{
    CheckTheFormFieldsMessage = "Your custom message...",
    RedirectDelay = 6000,
    DebugMode = true
});

View:

var formConfig = new FormConfig(ViewContext)
{
    FormId = "ProductForm",
    FormTitle = "New Product",
    BeforeSubmit = "ProductFormBeforeSubmit", // optional
    Callback = "ProductFormCallback" // optional,
};

// <form id="@formConfig.FormId" asp-controller="Home" asp-action="Save"
// ...

@await Html.RenderFormScript(formConfig)

Controller:

[HttpPost, FormValidator]
public IActionResult Save(FormViewModel viewModel)

Upvotes: 0

Jeremy Skinner
Jeremy Skinner

Reputation: 1461

The list of validators supported on the client is on this page and are as follows:

  • NotNull/NotEmpty (required)
  • Matches (regex)
  • InclusiveBetween (range)
  • CreditCard
  • Email
  • EqualTo (cross-property equality comparison)
  • Length

Upvotes: 26

daanl
daanl

Reputation: 44

So far i know there is no list, you could create your own client side validator so create that createrthen works also on client side

Upvotes: 0

Related Questions