Skip to content

Issue when binding DateTime to input type="time" #41731

Closed
@MarvinKlein1508

Description

@MarvinKlein1508

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Consider this code:

<input type="time" @bind-value="Input.AnyPropertyWhichIsOfTypeDateTime" class="form-control" placeholder="Time" />

Now consider the bound property to have a value like:
new DateTime(2022, 5, 18, 12, 22, 30);

As you can see, this value has the seconds set to 30.

.NET 5 displays the Input like this:
grafik

if you do the same thing with .NET 6 then the seconds will be displayed as well but the control is invalid because Step is set to 60 by default. So this control does not expect any seconds at all which results in a validation error from HTML5.
grafik

grafik

This is really annoying because most databases saves the seconds by default.

Expected Behavior

It should work exactly like in .NET 5

Steps To Reproduce

  1. Create a new project
  2. Create a model which holds a datetime property
  3. bind this property to <input type="time">
  4. Set the value to DateTime.Now
  5. Test with .NET 5 and then .NET 6

Exceptions (if any)

grafik

.NET Version

6.0.300

Anything else?

.NET SDK (gemäß "global.json"):
Version: 6.0.300
Commit: 8473146e7d

Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.300\

Host (useful for support):
Version: 6.0.5
Commit: 70ae3df4a6

.NET SDKs installed:
3.1.419 [C:\Program Files\dotnet\sdk]
5.0.404 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor Componentsfeature-renderingFeatures dealing with how blazor renders componentsinvestigate

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions