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
35.46k stars 10.03k forks source link

Asp-for and Date Inputs not showing the stored value by default #22182

Open elaine-jackson opened 4 years ago

elaine-jackson commented 4 years ago

Describe the bug

When using an asp-for input, if displaying a default value (for example an edit form), by default unlike with strings or numbers, the date is not available and it's blank. To fix this you currently have to overwrite the value= attribute to inject the YYYY-MM-DD. Based on how other values are handled, this should be done implicitly. The bug is that instead of YYYY-MM-DD, you get a C# style DateTime string which isn't supported by the HTML5 standard. It needs to be converted before being passed to the user. I noticed that a DateTime input is not included in the MVC unit tests.

                <input asp-for="Input.DateOfBirth" value="@Model.Input.DateOfBirth.Substring(6,4)-@Model.Input.DateOfBirth.Substring(0,2)-@Model.Input.DateOfBirth.Substring(3,2)" class="form-control" />

To Reproduce

Create a form using asp-for tag helper that modifies a stored date object.

Further References:

I found the following information when tracking down this bug.

Further technical details

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.202
 Commit:    6ea70c8dca

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

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  3.1.101 [C:\Program Files\dotnet\sdk]
  3.1.200 [C:\Program Files\dotnet\sdk]
  3.1.202 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
elaine-jackson commented 4 years ago

Interesting in that the tag helper should be formatting it based on the code at https://github.com/dotnet/aspnetcore/blob/90e89e970877a39cb048bb6f0e59551351f661c3/src/Mvc/Mvc.TagHelpers/src/InputTagHelper.cs#L468 and it's not. That block of code acknowledges the required RFC for filling to value attribute.

mkArtakMSFT commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.