Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding to input datetime-local deletes day when entering 0 first #44796

Closed
1 task done
MarvinKlein1508 opened this issue Oct 31, 2022 · 2 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@MarvinKlein1508
Copy link

MarvinKlein1508 commented Oct 31, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Binding to an input of type datetime-local behaves different from the default HTML behaviour.

Take a look on this:
blazor-bind

As you can see when I enter "0" for month it resets the input to a default datetime. When I press only the corresponding number of the month it works as expected. This also happens when you enter a 0 first on day.

The code for this is:

<div class="form-floating mb-3">
    <input type="datetime-local" @bind="Input.Von" @bind:format="yyyy-MM-ddTHH:mm:ss" class="form-control" id="besuch-anmelden-von" placeholder="Von" />
    <label for="besuch-anmelden-von">Von</label>
    <ValidationMessage For="() => Input.Von" />
</div>

Now lets compare it to blank HTML:
blank-html

As you can see in plain HTML the input does not reset when typing a 0 first.

<input type="datetime-local" />

Expected Behavior

It should work just like in HTML. Most people will type 08 to enter the month, not just 8. However both options should be possible.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

dotnet --info .NET SDK: Version: 6.0.402 Commit: 6862418796 Laufzeitumgebung: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.402\ global.json file: Not found Host: Version: 6.0.10 Architecture: x64 Commit: 5a400c212a .NET SDKs installed: 6.0.402 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Download .NET: https://aka.ms/dotnet-download Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

Anything else?

This might be connected with #40660

@MarvinKlein1508 MarvinKlein1508 changed the title Binding to input datetime-local deletes day when entering 0 for month Binding to input datetime-local deletes day when entering 0 first Oct 31, 2022
@MarvinKlein1508
Copy link
Author

There is a workaround to prevent this behaviour. Preventing the property from being set to the default value. It works but now you won't be able to set it to the default value of datetime at all. Luckily I can ignore this in my case.


public DateTime Von
{
    get => _von; 
    set
    {
        if(value == new DateTime())
        {
            return;
        }

        _von = value;
    }
}

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Oct 31, 2022
@mkArtakMSFT
Copy link
Member

Tanks for contacting us. This seems to be the same #43824

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Oct 31, 2022
@ghost ghost added the Status: Resolved label Oct 31, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants