{"id":19100027,"url":"https://github.com/Blazored/FluentValidation","last_synced_at":"2025-04-18T17:32:33.827Z","repository":{"id":37493464,"uuid":"191837358","full_name":"Blazored/FluentValidation","owner":"Blazored","description":"A library for using FluentValidation with Blazor","archived":false,"fork":false,"pushed_at":"2024-10-07T13:12:53.000Z","size":10099,"stargazers_count":594,"open_issues_count":49,"forks_count":85,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-10-29T17:29:25.035Z","etag":null,"topics":["blazor","blazored","csharp","fluentvalidation","hacktoberfest","nuget"],"latest_commit_sha":null,"homepage":"https://blazored.github.io/FluentValidation/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blazored.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["chrissainty"]}},"created_at":"2019-06-13T21:45:47.000Z","updated_at":"2024-10-29T17:00:49.000Z","dependencies_parsed_at":"2024-02-18T16:31:11.642Z","dependency_job_id":"9b59685a-268a-4264-be52-5053446faae5","html_url":"https://github.com/Blazored/FluentValidation","commit_stats":{"total_commits":52,"total_committers":19,"mean_commits":2.736842105263158,"dds":0.6730769230769231,"last_synced_commit":"38d8fe49a8f5ee6260fd79c8d9ec74a0b4efbb8c"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blazored%2FFluentValidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blazored%2FFluentValidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blazored%2FFluentValidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blazored%2FFluentValidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blazored","download_url":"https://codeload.github.com/Blazored/FluentValidation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783092,"owners_count":17201903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazored","csharp","fluentvalidation","hacktoberfest","nuget"],"created_at":"2024-11-09T03:52:26.445Z","updated_at":"2024-11-09T03:52:56.115Z","avatar_url":"https://github.com/Blazored.png","language":"C#","readme":"# FluentValidation\nA library for using FluentValidation with Blazor\n\n[![Nuget version](https://img.shields.io/nuget/v/Blazored.FluentValidation.svg?logo=nuget)](https://www.nuget.org/packages/Blazored.FluentValidation/)\n[![Nuget downloads](https://img.shields.io/nuget/dt/Blazored.FluentValidation?logo=nuget)](https://www.nuget.org/packages/Blazored.FluentValidation/)\n![Build \u0026 Test Main](https://github.com/Blazored/FluentValidation/workflows/Build%20\u0026%20Test%20Main/badge.svg)\n\n## Installing\n\nYou can install from Nuget using the following command:\n\n`Install-Package Blazored.FluentValidation`\n\nOr via the Visual Studio package manger.\n\n## Basic Usage\nStart by add the following using statement to your root `_Imports.razor`.\n\n```razor\n@using Blazored.FluentValidation\n```\n\nYou can then use it as follows within a `EditForm` component.\n\n```razor\n\u003cEditForm Model=\"@_person\" OnValidSubmit=\"@SubmitValidForm\"\u003e\n    \u003cFluentValidationValidator /\u003e\n    \u003cValidationSummary /\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eName: \u003c/label\u003e\n        \u003cInputText @bind-Value=\"@_person.Name\" /\u003e\n    \u003c/p\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eAge: \u003c/label\u003e\n        \u003cInputNumber @bind-Value=\"@_person.Age\" /\u003e\n    \u003c/p\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eEmail Address: \u003c/label\u003e\n        \u003cInputText @bind-Value=\"@_person.EmailAddress\" /\u003e\n    \u003c/p\u003e\n\n    \u003cbutton type=\"submit\"\u003eSave\u003c/button\u003e\n\u003c/EditForm\u003e\n\n@code {\n    private Person _person = new();\n\n    private void SubmitValidForm()\n        =\u003e Console.WriteLine(\"Form Submitted Successfully!\");\n}\n```\n\n## Finding Validators\nBy 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.\n\nYou 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.\n\n```html\n\u003cFluentValidationValidator DisableAssemblyScanning=\"@true\" /\u003e\n```\n\nYou 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.\n\n**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.\n\nThe validator must be publicly accessible and inherit directly from `AbstractValidator\u003cT\u003e`.\n\n## Async Validation\nIf you're using async validation, you can use the `ValidateAsync` method on the `FluentValidationValidator`.\n\n```razor\n\u003cEditForm Model=\"@_person\" OnSubmit=\"@SubmitFormAsync\"\u003e\n    \u003cFluentValidationValidator @ref=\"_fluentValidationValidator\" /\u003e\n    \u003cValidationSummary /\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eName: \u003c/label\u003e\n        \u003cInputText @bind-Value=\"@_person.Name\" /\u003e\n    \u003c/p\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eAge: \u003c/label\u003e\n        \u003cInputNumber @bind-Value=\"@_person.Age\" /\u003e\n    \u003c/p\u003e\n\n    \u003cp\u003e\n        \u003clabel\u003eEmail Address: \u003c/label\u003e\n        \u003cInputText @bind-Value=\"@_person.EmailAddress\" /\u003e\n    \u003c/p\u003e\n\n    \u003cbutton type=\"submit\"\u003eSave\u003c/button\u003e\n\n\u003c/EditForm\u003e\n\n@code {\n    private Person _person = new();\n    private FluentValidationValidator? _fluentValidationValidator;\n\n    private async void SubmitFormAsync()\n    {\n        if (await _fluentValidationValidator!.ValidateAsync())\n        {\n            Console.WriteLine(\"Form Submitted Successfully!\");\n        }\n    }\n}\n```\n\n## RuleSets\n[RuleSets](https://docs.fluentvalidation.net/en/latest/rulesets.html) allow validation rules to be grouped and executed together while ignoring other rules. RulesSets are supported in two ways.\n\nThe first is setting RuleSets via the `Options` parameter on the `FluentValidationValidator` component.\n\n```razor\n\u003cFluentValidationValidator Options=\"@(options =\u003e options.IncludeRuleSets(\"Names\"))\" /\u003e\n```\n\nThe second is when manually validating the model using the `Validate` or `ValidateAsync` methods. \n\n```razor\n\u003cFluentValidationValidator @ref=\"_fluentValidationValidator\" /\u003e\n\n@code {\n    private FluentValidationValidator? _fluentValidationValidator;\n\n    private void PartialValidate()\n        =\u003e _fluentValidationValidator?.Validate(options =\u003e options.IncludeRuleSets(\"Names\"));\n}\n```\n\n## Access to full `ValidationFailure`\nIf you need details about the specifics of a validation result (e.g. its `Severity`), you can access the result of the \nlast validation by calling the `GetFailuresFromLastValidation` method on the `FluentValidationValidator` component.\n\n```razor\n\u003cdiv class=\"validation-message @GetValidationClass()\"\u003e\n    \u003cinput type=\"text\" @bind=\"@_person.Name\" /\u003e\n\u003c/div\u003e\n\n@code {\n    private FluentValidationValidator? _fluentValidationValidator;\n\n    private string GetValidationClass() \n    {\n        var lastResult = _fluentValidationValidator?.GetFailuresFromLastValidation();\n        if (lastResult is null || !lastResult.Any())\n        {\n            return \"valid\";\n        }\n        if (lastResult.Any(failure =\u003e failure.Severity == Severity.Error))\n        {\n            return \"invalid\";\n        }\n        return \"warning\";\n    }\n}\n```","funding_links":["https://github.com/sponsors/chrissainty"],"categories":["hacktoberfest","csharp"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlazored%2FFluentValidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlazored%2FFluentValidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlazored%2FFluentValidation/lists"}