GreatIdeas.Blazored.FluentValidation 1.0.0

dotnet add package GreatIdeas.Blazored.FluentValidation --version 1.0.0
NuGet\Install-Package GreatIdeas.Blazored.FluentValidation -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GreatIdeas.Blazored.FluentValidation" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GreatIdeas.Blazored.FluentValidation --version 1.0.0
#r "nuget: GreatIdeas.Blazored.FluentValidation, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GreatIdeas.Blazored.FluentValidation as a Cake Addin
#addin nuget:?package=GreatIdeas.Blazored.FluentValidation&version=1.0.0

// Install GreatIdeas.Blazored.FluentValidation as a Cake Tool
#tool nuget:?package=GreatIdeas.Blazored.FluentValidation&version=1.0.0

FluentValidation

A library for using FluentValidation with Blazor. This is a fork of the blazored.fluentvalidation where packages are updated to be current with the FluentValidation packages.

Installing

You can install from Nuget using the following command:

Install-Package GreatIdeas.Blazored.FluentValidation

Or via the Visual Studio package manger.

Basic Usage

Start by add the following using statement to your root _Imports.razor.

@using Blazored.FluentValidation

You can then use it as follows within a EditForm component.

<EditForm Model="@_person" OnValidSubmit="@SubmitValidForm">
    <FluentValidationValidator />
    <ValidationSummary />

    <p>
        <label>Name: </label>
        <InputText @bind-Value="@_person.Name" />
    </p>

    <p>
        <label>Age: </label>
        <InputNumber @bind-Value="@_person.Age" />
    </p>

    <p>
        <label>Email Address: </label>
        <InputText @bind-Value="@_person.EmailAddress" />
    </p>

    <button type="submit">Save</button>
</EditForm>

@code {
    private Person _person = new();

    private void SubmitValidForm()
        => Console.WriteLine("Form Submitted Successfully!");
}

Finding Validators

By default, the component will check for validators registered with DI first. If it can't find, any it will then try scanning the applications assemblies to find validators using reflection.

You can control this behaviour using the DisableAssemblyScanning parameter. If you only wish the component to get validators from DI, set the value to true and assembly scanning will be skipped.

<FluentValidationValidator DisableAssemblyScanning="@true" />

You can find examples of different configurations in the sample projects. The Blazor Server project is configured to load validators from DI only. The Blazor WebAssembly project is setup to load validators using reflection.

Note: When scanning assemblies the component will swallow any exceptions thrown by that process. This is to stop exceptions thrown by scanning third party dependencies crashing your app.

Async Validation

If you're using async validation, you can use the ValidateAsync method on the FluentValidationValidator.

<EditForm Model="@_person" OnSubmit="@SubmitFormAsync">
    <FluentValidationValidator @ref="_fluentValidationValidator" />
    <ValidationSummary />

    <p>
        <label>Name: </label>
        <InputText @bind-Value="@_person.Name" />
    </p>

    <p>
        <label>Age: </label>
        <InputNumber @bind-Value="@_person.Age" />
    </p>

    <p>
        <label>Email Address: </label>
        <InputText @bind-Value="@_person.EmailAddress" />
    </p>

    <button type="submit">Save</button>

</EditForm>

@code {
    private Person _person = new();
	private FluentValidationValidator? _fluentValidationValidator;

    private void SubmitFormAsync()
    {
		if (await _fluentValidationValidator!.ValidateAsync())
        {
            Console.WriteLine("Form Submitted Successfully!");
        }
    }
}

RuleSets

RuleSets allow validation rules to be grouped and executed together while ignoring other rules. RulesSets are supported in two ways.

The first is setting RuleSets via the Options parameter on the FluentValidationValidator component.

<FluentValidationValidator Options="@(options => options.IncludeRuleSets("Names"))" />

The second is when manually validating the model using the Validate or ValidateAsync methods.

<FluentValidationValidator @ref="_fluentValidationValidator" />

@code {
    private FluentValidationValidator? _fluentValidationValidator;

    private void PartialValidate()
        => _fluentValidationValidator?.Validate(options => options.IncludeRuleSets("Names"));
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,261 8/16/2022