Skip to content

Commit

Permalink
v2.0.4 - made validations optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ddjerqq committed Mar 6, 2024
1 parent 1d1e442 commit 9407954
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ QuickForm has two types of validation
- `DataAnnotationsValidator`
- [`Blazored.FluentValidationValidator`](https://github.com/Blazored/FluentValidation)

Both of which can be disabled with setting `EnableDataAnnotationsValidation` and `EnableFluentValidation` parameters to false.

## DataAnnotationAttributes

```csharp
Expand Down
11 changes: 9 additions & 2 deletions src/QuickForm/Components/QuickForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
<EditForm EditContext="EditContext"
OnSubmit="@OnSubmit" OnInvalidSubmit="@OnInvalidSubmit" OnValidSubmit="@OnValidSubmit"
AdditionalAttributes="@(AdditionalAttributes as IReadOnlyDictionary<string, object>)">
<DataAnnotationsValidator/>
<FluentValidationValidator/>
@if (EnableDataAnnotationsValidation)
{
<DataAnnotationsValidator/>
}

@if (EnableFluentValidation)
{
<FluentValidationValidator/>
}

@foreach (var field in Fields)
{
Expand Down
16 changes: 14 additions & 2 deletions src/QuickForm/Components/QuickForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ public partial class QuickForm<TEntity> : ComponentBase, IDisposable
[Parameter]
public string InvalidClass { get; set; } = "invalid";

/// <summary>
/// Gets or sets the flag to enable or disable data annotations validation.
/// </summary>
[Parameter]
public bool EnableDataAnnotationsValidation { get; set; } = true;

/// <summary>
/// Gets or sets the flag to enable or disable fluent validation.
/// </summary>
[Parameter]
public bool EnableFluentValidation { get; set; } = true;

/// <summary>
/// Gets or sets the template for the fields in this form.
/// </summary>
[Parameter]
public virtual RenderFragment<IQuickFormField> ChildContent { get; set; } = _ => builder =>
public RenderFragment<IQuickFormField> ChildContent { get; set; } = _ => builder =>
{
builder.OpenElement(0, "div");
builder.AddContent(1, "You must provide ChildContent unless you are using a custom form template.");
Expand All @@ -47,7 +59,7 @@ public partial class QuickForm<TEntity> : ComponentBase, IDisposable
/// Make sure to give this button `type="submit"` to make it work.
/// </note>
[Parameter]
public virtual RenderFragment? SubmitButtonTemplate { get; set; }
public RenderFragment? SubmitButtonTemplate { get; set; }

/// <summary>
/// Gets or sets the callback to be invoked when the model changes.
Expand Down
2 changes: 1 addition & 1 deletion src/QuickForm/QuickForm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageTags>aspnetcore, components, blazor, forms</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>2.0.3</Version>
<Version>2.0.4</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 9407954

Please sign in to comment.