https://blazorrepl.telerik.com/GeYMbZQk22cmnlsN33
When adding a new record and editing `Field1`, the validation tooltip and k-invalid styling appear if the user is entering any value that triggers the custom ValidationAttribute. If the user presses enter, the validation correctly prevents a new record from being created. However, k-invalid styling is replaced with k-valid styling, and the validation tooltip disappears.
How can the k-invalid styling and validation tooltip persist when the user presses enter with an invalid input?
2 Answers, 1 is accepted
The custom validation attribute returned a `ValidationResult` without identifying the affected member:
```csharp
return new ValidationResult(ErrorMessage);
```
During field validation, Blazor associates the result with the field being edited. However, when the Grid validates the entire model during submission, a result without a member name is associated with the model instead of the field. Consequently, submission is blocked, but the field loses its validation tooltip and `k-invalid` styling.
Returning the field name fixes the behavior:
```csharp
return new ValidationResult(
ErrorMessage,
[validationContext.MemberName!]);
```
Microsoft documents this requirement here:
https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation#custom-validation-attributes
I tested the change with Telerik UI for Blazor 15.1.0:
- With inline editing, the invalid styling and tooltip remain after attempting to submit.
- With in-cell editing, the invalid value can no longer be submitted.
- Without the member name, I can still reproduce the original inline behavior and can submit an invalid value in in-cell mode.
This appears to be standard Blazor validation behavior rather than a Telerik-specific validation defect.
Yes indeed, this requirement is also discussed in the following KB articles:
Hi Leland,
I confirm that your observations on the current behavior are correct. To address this scenario, a public item for an enhancement in the Incell and Inline editing has already been submitted on our public feedback portal: Incell & Inline Editing must work with ValidationResult for custom validation attributes. I voted for the item on your behalf and raised its priority.
You can also subscribe to it to receive email notifications for further status updates.
Once implemented, the enhancement will allow you to achieve the desired validation behavior.
Regards,
Hristian Stefanov
Progress Telerik
Do you have a stake in the designеr-developer collaboration process? If so, take our survey to share your perspective and become part of this global research. You’ll be among the first to know once the results are out.
-> Start The State of Designer-Developer Collaboration Survey 2024
In fact, it seems to be requesting a change that would only aggravate my issue. It states "When I override the IsValid method to return a ValidationResult the Incell & Inline edit modes allow the editing to be continued even if an invalid value is present." This describes the current behavior, and is actually desired. The editing needs to continue so that the user has the opportunity to correct whatever is causing the validation issue, but there needs to be styling to indicate which rows have the issues, along with tooltips to provide details in complex scenarios. If they wish to abandon the edit, they can still press a cancel command button, if present (I excluded one from my example, for simplicity).
I also note that there is no workaround to use until this is implemented, as is common in other bug reports or feature requests I have seen. Can anything be done now to get the k-invalid styling to persist in this situation?
Hi Leland,
Thank you for getting back to me.
Your feedback on the linked feature request suggests that the description might not be clear enough. When it says, "the Incell & Inline edit modes allow editing to continue even if an invalid value is present," it means users can move to the next cell without correcting the invalid input, which is not the intended behavior. The correct approach should prevent moving forward until a valid value is entered, with the red border persisting until then.
You are right that there isn’t a workaround at the moment. If any workaround becomes available, I’ll share it in the comments of the public item.
Let me know if I'm still missing something from the scenario.
Kind Regards,
Hristian
k-valid styling being applied when validation is preventing row creation / updating seems like a bug.
Hi Leland,
I confirm that the k-valid styling isn't being applied correctly because Grid Incell & Inline Editing currently doesn't work with ValidationResult for custom validation attributes.
Rest assured, the item I linked will fully cover your scenario and display the validation CSS class correctly. Keep an eye on it for further updates.
Kind Regards,
Hristian
