Closed HTK-SSE closed 2 years ago
Thanks for contacting us. You're missing to include MemberName as part of validation result. Here are the docs to help you with that: https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-6.0#custom-validation-attributes
Problem with Blazor EditForm / UI validation:
If you´re using any custom data annotations validation attributes and submit an invalid model, the Validator correctly recognize that it´s invalid. Also the validation summary will display correctly but the input element with the binded value as well as the ValidationMessage razor element looses their error states after submit.
public class MinDateNow : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) => ((value as DateTime?).Value >= DateTime.Now) ? ValidationResult.Success : new ValidationResult("Das Start-Datum darf nicht in der Vergangenheit liegen."); }
[Required(ErrorMessage = "Es muss immer ein Start-Datum bestimmt werden.")]
[MinDateNow]
public DateTime? ValidFrom { get; set; } = DateTime.Now;
<InputDate TValue="DateTime?" @bind-Value="Model.Deviation.ValidUntil" />
<ValidationMessage For="(() => Model.Deviation.ValidUntil)" style="font-size:small;" />