I'm trying to implement fluent validation in blazorise datagrid.
Steps:
services
.AddBlazorise();
services
.AddBootstrapProviders()
.AddFontAwesomeIcons()
.AddBlazoriseFluentValidation();`
Markup for datagrid
<DataGrid TItem="ProductBrandVM" class="table table-responsive-lg table-bordered table-striped table-sm mb-0 Dtable"
Data="@productbrandsResult.Data"
@bind-SelectedRow="@selectedProductBrand"
Editable
Responsive
UseValidation
ShowPager
CommandMode="DataGridCommandMode.ButtonRow"
RowUpdated="@OnRowUpdatedAsync"
RowInserted="@OnRowInsertedAsync"
Filterable FilterMode="DataGridFilterMode.Menu"
EditMode="editMode">
<DataGridColumns>
<DataGridColumn Field="@nameof(ProductBrandVM.ProductBrandCode)" Caption="Code" Editable />
<DataGridColumn Field="@nameof(ProductBrandVM.ProductBrandName)" Caption="Name" Editable />
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false" CancelCommandAllowed>
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" Color="Color.Primary" Clicked="@context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="@context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>
</DataGridColumns>
<ButtonRowTemplate>
<Button Color="Color.Success" Clicked="context.NewCommand.Clicked">New</Button>
<Button Color="Color.Primary" Disabled="(selectedProductBrand is null)" Clicked="context.EditCommand.Clicked">Edit</Button>
<Button Color="Color.Danger" Disabled="(selectedProductBrand is null)" Clicked="context.DeleteCommand.Clicked">Delete</Button>
<Button Color="Color.Link" Clicked="context.ClearFilterCommand.Clicked">Clear Filter</Button>
</ButtonRowTemplate>
</DataGrid>
Code:
public void CheckName(ValidatorEventArgs validationArgs)
{
ValidationRule.IsNotEmpty(validationArgs);
if (validationArgs.Status == ValidationStatus.Error)
{
validationArgs.ErrorText = "Name can't be empty.";
}
}
<DataGridColumn Field="@nameof(ProductBrandVM.ProductBrandName)"
Validator="@CheckName" Caption="Name" Editable />
When I try to create a record with empty fields the popup window closes automatically.