dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.82k stars 9.84k forks source link

Blazor Static SSR ParsableConverter mapping error message customization #56484

Open sgarnovsky opened 1 week ago

sgarnovsky commented 1 week ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

https://github.com/dotnet/aspnetcore/blob/94259788d58e16ba753900b4bf855a6aee08dcb1/src/Components/Endpoints/src/FormMapping/Converters/ParsableConverter.cs#L22 var segment = reader.GetLastPrefixSegment(); reader.AddMappingError(FormattableStringFactory.Create(FormDataResources.ParsableMappingError, value, **segment**), value); result = default!; return false; It means what we don't have a simple ability to format this validation message better. The main problem as it doen't use a property display attribute caption, just a property name in a model class.

Describe the solution you'd like

That's possible it can be a quite handy thing when we have an ability to customize the validation message in a some simple way. MVC/Razor Pages projects provide AttemptedValueIsInvalidAccessor inside the ModelBindingMessageProvider.

Blazor static SSR doesn't have any options for customization in this case. ParsableConverter is an "internal" class as well as other related classes. So there is no a simple way to override them in a user code.

Additional context

No response

mkArtakMSFT commented 1 week ago

Can you please provide more details about your scenario. We'd like to understand how you plan to use this and how do you expect this message to show up to the end user so that you need customization?

sgarnovsky commented 1 week ago

Can you please provide more details about your scenario. We'd like to understand how you plan to use this and how do you expect this message to show up to the end user so that you need customization?

I need a custom implementation of a Date Input control. Described it here: Blazor static SSR support to override ParsableConverter for mapping non invariant DateTime values

I know if we use [input type=date] there is no simple way to post invalid date value for this control.

I am going to use a simple [input type=text] to enter date values (in a custom date format), so a user can simply enter invalid value in this case and see a mapping type error message which refers a model property name instead of a field caption.