ant-design-blazor / ant-design-blazor/ant-design-blazor

DatePicker API needs to be extended to allow for conversion to and from custom values

Abierto
#3,039 4 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
C#
Estrellas
6.2k
Forks
1.2k
Merge medio
1 d 22 h
PR fusionados (30 d)
1

Descripción

### Describe the bug

We use the [NodaTime](https://github.com/nodatime/nodatime) library's [LocalDate](https://nodatime.org/2.2.x/api/NodaTime.LocalDate.html) struct but unfortunately it cannot be bound to DatePicker even though the fact that TValue exists would give you the idea that custom types are supported.

Obviously using System.Convert.ToDateTime is a broken approach that likely will not work with many custom types. The suggestion is simply to follow the same pattern you have with the Formatter and Parser parameters for InputNumber where you expose conversion functions Func and Func then I could supply args like date => NodaTime.FromDateTime(date) and value => value.ToDateTimeUnspecified() respectively where the conversion functions are only invoked when the nullable DateTime? underlying value has a value.

### Steps to reproduce (please include code)
```csharp

@code {
public sealed record FormModel(LocalDate? RequestedDate);
private FormModel _formModel = new();
}
```

### Exceptions (if any)
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
at System.Convert.ToDateTime(Object value, IFormatProvider provider)
at AntDesign.DatePicker`1[[System.Nullable`1[[NodaTime.LocalDate, NodaTime, Version=3.0.3.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ProcessDefaults()
at AntDesign.DatePicker`1[[System.Nullable`1[[NodaTime.LocalDate, NodaTime, Version=3.0.3.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnInitialized()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

### Further technical details
- AntDesign Nuget Package version [0.13.3](https://www.nuget.org/packages/AntDesign/0.13.3)
- Include the output of `dotnet --info`
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.102\

Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb

.NET SDKs installed:
7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set
- The IDE Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.4.4

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.