Blazor.FluentValidation 1.0.0

dotnet add package Blazor.FluentValidation --version 1.0.0
                    
NuGet\Install-Package Blazor.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="Blazor.FluentValidation" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blazor.FluentValidation" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Blazor.FluentValidation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blazor.FluentValidation --version 1.0.0
                    
#r "nuget: Blazor.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.
#:package Blazor.FluentValidation@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazor.FluentValidation&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Blazor.FluentValidation&version=1.0.0
                    
Install as a Cake Tool

Blazor.FluentValidation

Blazor.FluentValidation

๐Ÿš€ Integrasi otomatis FluentValidation ke dalam <EditForm> Blazor.
โœจ Kompatibel dengan .NET 8+, mendukung nested validation, DI, dan validasi per field secara real-time!

NuGet License: MIT


๐Ÿงฉ Fitur Utama

  • ๐Ÿ”— Integrasi langsung ke <EditForm> โ€” tanpa konfigurasi kompleks
  • ๐Ÿ’‰ Support ValidatorType via Dependency Injection (DI)
  • ๐Ÿ› ๏ธ Support ValidatorInstance tanpa DI (manual)
  • ๐Ÿง  Validasi properti nested seperti Address.City otomatis tampil
  • โšก Validasi real-time saat field diubah (OnFieldChanged)
  • ๐Ÿ” Kompatibel dengan [SupplyParameterFromForm] (.NET 8+ Interactive Rendering)

๐Ÿ“ฆ Instalasi

dotnet add package Blazor.FluentValidation

๐Ÿ”ง Registrasi DI (jika pakai ValidatorType)

using FluentValidation;
builder.Services.AddValidatorsFromAssemblyContaining<PersonValidator>();

// atau untuk banyak assembly
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
builder.Services.AddValidatorsFromAssemblies(assemblies, includeInternalTypes: true);

โœ… Contoh Penggunaan

๐Ÿงท Mode 1: ValidatorType (dari DI)

<EditForm Model="@person" OnValidSubmit="@HandleSubmit" FormName="formA">
    <FluentValidationExtension ValidatorType="typeof(PersonValidator)" />
    <InputText @bind-Value="person.Name" />
    <ValidationMessage For="@(() => person.Name)" />
</EditForm>

โœ๏ธ Mode 2: ValidatorInstance (manual)

<EditForm Model="@person" OnValidSubmit="@HandleSubmit" FormName="formB">
    <FluentValidationExtension ValidatorInstance="new PersonValidator()" />
    <InputText @bind-Value="person.Name" />
    <ValidationMessage For="@(() => person.Name)" />
</EditForm>

๐Ÿ‘ช Contoh Nested Validation (Parent-Child)

๐Ÿ”น Model

public class Person
{
    public string Name { get; set; } = string.Empty;
    public Address Address { get; set; } = new();
}

public class Address
{
    public string Street { get; set; } = string.Empty;
    public string City { get; set; } = string.Empty;
}

๐Ÿ”น Validator

public class PersonValidator : AbstractValidator<Person>
{
    public PersonValidator()
    {
        RuleFor(p => p.Name).NotEmpty().WithMessage("Nama wajib diisi.");
        RuleFor(p => p.Address).SetValidator(new AddressValidator());
    }
}

public class AddressValidator : AbstractValidator<Address>
{
    public AddressValidator()
    {
        RuleFor(a => a.Street).NotEmpty().WithMessage("Jalan wajib diisi.");
        RuleFor(a => a.City).NotEmpty().WithMessage("Kota wajib diisi.");
    }
}

๐Ÿ”น Razor Form

<EditForm Model="@person" OnValidSubmit="@HandleSubmit" FormName="nestedForm">
    <FluentValidationExtension ValidatorType="typeof(PersonValidator)" />

    <InputText @bind-Value="person.Name" />
    <ValidationMessage For="@(() => person.Name)" />

    <InputText @bind-Value="person.Address.Street" />
    <ValidationMessage For="@(() => person.Address.Street)" />

    <InputText @bind-Value="person.Address.City" />
    <ValidationMessage For="@(() => person.Address.City)" />
</EditForm>

โš ๏ธ Penting untuk .NET 8+

Jika Anda menggunakan [SupplyParameterFromForm], pastikan menyertakan FormName:

<EditForm FormName="uniqueFormName" ... />

Tanpa FormName, Blazor akan menampilkan error seperti:

The POST request does not specify which form is being submitted.

๐Ÿ’ฌ Kontribusi & Dukungan

Kontribusi terbuka! Silakan laporkan issue, ajukan fitur, atau buat pull request di:

๐Ÿ”— https://github.com/ganiputras/Blazor.FluentValidation

โš–๏ธ Lisensi

Blazor.FluentValidation dirilis di bawah MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 94 7/30/2025

Blazor.FluentValidation v1.0.0

โœ… Fitur:
- Integrasi otomatis FluentValidation dalam Blazor `EditForm`.
- Mendukung penggunaan `ValidatorType` dari DI dan `ValidatorInstance` secara manual.
- Kompatibel dengan validasi built-in Blazor.
- Dukungan validasi real-time melalui `OnFieldChanged`.

📚 Dokumentasi:
🔗 https://github.com/ganiputras/Blazor.FluentValidation