Skip to content

Commit

Permalink
Add SetDataAnnotationsValidation method to disable CRUD data annotati…
Browse files Browse the repository at this point in the history
…ons validation
  • Loading branch information
gustavnavar committed Mar 26, 2022
1 parent 60eae53 commit 6f4757d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions GridBlazor/CGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ public string[] GetPrimaryKeys()
return values.ToArray();
}

public bool DataAnnotationsValidation { get; set; } = true;

private static readonly Task<bool> InsertColumnSucceded = Task.FromResult(true);
private static readonly Task<bool> InsertColumnFailed = Task.FromResult(false);
/// <inheritdoc/>
Expand Down
6 changes: 6 additions & 0 deletions GridBlazor/Client/GridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ public IGridClient<T> ODataCrud(bool createEnabled, Func<T, bool> readEnabled,
return this;
}

public IGridClient<T> SetDataAnnotationsValidation(bool enabled = true)
{
_source.DataAnnotationsValidation = enabled;
return this;
}

public IGridClient<T> SetCrudButtonLabels(string createLabel, string readLabel, string updateLabel,
string deleteLabel)
{
Expand Down
5 changes: 5 additions & 0 deletions GridBlazor/Client/IGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ IGridClient<T> ODataCrud(bool createEnabled, bool readEnabled, bool updateEnable
IGridClient<T> ODataCrud(bool createEnabled, Func<T, bool> readEnabled,
Func<T, bool> updateEnabled, Func<T, bool> deleteEnabled, ICrudFileService<T> crudFileService = null);

/// <summary>
/// Enable or disable annotations validation for CRUD views
/// </summary>
IGridClient<T> SetDataAnnotationsValidation(bool enabled = true);

/// <summary>
/// Configure CRUD button labels
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>3.2.3</Version>
<Version>3.2.4</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
7 changes: 5 additions & 2 deletions GridBlazor/ICGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public interface ICGrid : IGrid, IGridOptions
/// </summary>
string[] GetPrimaryKeys();

bool DataAnnotationsValidation { get; set; }

IGridSettingsProvider Settings { get; }

IEnumerable<object> SelectedItems { get; set; }
Expand Down Expand Up @@ -341,18 +343,19 @@ public interface ICGrid : IGrid, IGridOptions
int DeleteConfirmationWidth { get; set; }

int DeleteConfirmationLabelWidth { get; set; }

/// <summary>
/// Header CRUD buttons
/// </summary>
bool HeaderCrudButtons { get; set; }

/// <summary>
/// Header CRUD buttons
/// Show errors on Grid when getting data
/// </summary>
bool ShowErrorsOnGrid { get; set; }

/// <summary>
/// Header CRUD buttons
/// Throw exceptions when getting data
/// </summary>
bool ThrowExceptions { get; set; }

Expand Down
7 changes: 5 additions & 2 deletions GridBlazor/Pages/GridCreateComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<div class="@GridComponent.GridCrudHeaderCssClass">@(string.IsNullOrWhiteSpace(GridComponent.Grid.CreateFormLabel) ? Strings.Add : GridComponent.Grid.CreateFormLabel)</div>

<EditForm Model="@Item" OnValidSubmit="@CreateItem" @ref="Form">
<DataAnnotationsValidator />
<ValidationSummary />
@if (GridComponent.Grid.DataAnnotationsValidation)
{
<DataAnnotationsValidator />
<ValidationSummary />
}
<p id="error" class="@GridComponent.GridErrorCssClass">@Error</p>
<div class="form-horizontal">
@foreach (var column in GridComponent.Grid.Columns)
Expand Down
7 changes: 5 additions & 2 deletions GridBlazor/Pages/GridUpdateComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<div class="@GridComponent.GridCrudHeaderCssClass">@(string.IsNullOrWhiteSpace(GridComponent.Grid.UpdateFormLabel) ? Strings.Edit : GridComponent.Grid.UpdateFormLabel)</div>

<EditForm Model="@Item" OnValidSubmit="@UpdateItem" @ref="Form">
<DataAnnotationsValidator />
<ValidationSummary />
@if (GridComponent.Grid.DataAnnotationsValidation)
{
<DataAnnotationsValidator />
<ValidationSummary />
}
<p id="error" class="@GridComponent.GridErrorCssClass">@Error</p>
<div class="form-horizontal">
@foreach (var column in GridComponent.Grid.Columns)
Expand Down

0 comments on commit 6f4757d

Please sign in to comment.