Skip to content

Commit

Permalink
SaveInternal | Add ValidateAll
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Moreira committed Oct 31, 2023
1 parent f239f68 commit f60b5b0
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,8 @@ public async Task Save()
if ( Data == null || editState == DataGridEditState.None )
return;

if ( UseValidation )
if ( !await ValidateAll() )
{
var result = PopupVisible
? await dataGridModalRef.ValidateAll()
: await dataGridRowEditRef.ValidateAll();

if ( !result )
return;
}

Expand All @@ -915,6 +910,23 @@ public async Task Save()

await InvokeAsync( StateHasChanged );
}

/// <summary>
/// Validates the current edit operation.
/// </summary>
/// <returns></returns>
public async Task<bool> ValidateAll()
{
if ( UseValidation )
{
var result = PopupVisible
? await dataGridModalRef.ValidateAll()
: await dataGridRowEditRef.ValidateAll();

return result;
}
return true;
}

/// <summary>
/// Saves all the tracked batch edit changes.
Expand All @@ -936,6 +948,14 @@ internal protected Task SaveBatch()
/// <returns></returns>
internal protected async Task SaveInternal()
{
if ( Data == null || editState == DataGridEditState.None )
return;

if ( !await ValidateAll() )
{
return;
}

if ( BatchEdit )
{
await SaveBatchItem();
Expand Down

0 comments on commit f60b5b0

Please sign in to comment.