Closed anderjoy closed 4 years ago
I don't see a crash here. However nullable types do get resetted to default
when the value
is empty which happens to the value browsers use for invalid date times.
Nullable values get resetted to default
, while non-nullable types retain the previous value if parsing fails:
https://github.com/aspnet/AspNetCore/blob/c7937640a4079465d36441724933eae5a9ca0085/src/Components/Web/src/Forms/InputBase.cs#L94. @SteveSandersonMS would you happen to know why we made that choice?
It’s because empty is considered a valid value for a nullable datetime, but not for a regular one. So we can only accept it in the former case.
I understood... Thanks
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Describe the bug
InputDate changes to null when entering a new date starting with zero (0).
For example, assuming the user enters 2020/01/02 and then decides to change the month to 02, the property is changed to null.
I think the problem is on this line: https://github.com/aspnet/AspNetCore/blob/c7937640a4079465d36441724933eae5a9ca0085/src/Components/Web/src/Forms/InputBase.cs#L88
When _nullableUnderlyingType == typeof (DateTime) the problem occurs because CurrentValue is set to default (null).
In my tests, I changed this line to:
And the problem has been resolved.
To Reproduce
Create a Blazor Server-Side Project, change the index.razor for:
Further technical details
Ambiente de runtime: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db
.NET Core SDKs installed: 2.2.401 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]