Hi,
This is my second Validation struggle this week.
I have a TelerikGrid displaying my Dtos.
This grid uses a FluentValidator.
I want to trigger the Validator for a specific DTO when the user clicks on a button on the row displaying the DTO.
The Validator rules are rather complex, let's say that if it is invalid when the user clicks the button, several grid columns from the row would need to turn red
My method bound to the button does trigger the validator correctly and I can see when it fails (the ValidationResult contains errors).
But none of the invalid controls are then displayed as having errors (red with errors).
Do I have to implement the logic manually?
I have to say that I do not have the slightest idea in which direction I should head.
My minimal current code looks like this:
<TelerikGrid @ref="@_gridRef"
TItem="MyDto"
OnRead="@ReadItems">
<GridSettings>
<GridValidationSettings>
<ValidatorTemplate>
<FluentValidationValidator Validator=@Validator />
</ValidatorTemplate>
</GridValidationSettings>
</GridSettings>
<GridToolBarTemplate> [...] </GridToolBarTemplate>
<DetailTemplate Context="ctx">
[...] /* We will talk about how to flag this DetailTemplate's fields as arror later*/
</DetailTemplate>
<GridColumns>
<GridColumn Field="@(nameof(MyDto.MyProp))" Title="..."/>
<GridColumn Field="@(nameof(MyDto.MyProp2))" Title="..."/>
<GridColumn Field="@(nameof(MyDto.MyProp3))" Title="..."/>
<GridColumn Title="Action"
<Template>
<TelerikButton OnClick="@(() => Update(context as MyDto))" Title="Title" />
</Template>
</GridColumn>
[...]
</GridColumns>
</TelerikGrid>
In this case I would like let's say GridColumn 2 and 3 to be displayed as invalid.
My button Method code is as follows:
private async Task Update(MyDto myDto) { ValidationResult result = Validator.Validate(myDto); if (!result.Errors.Any()) { await myService.Update(myDto); await RefreshTable(); } //else //{ // await Task.Delay(50); // StateHasChanged(); //} }
Thx in advance foy your assistance.