aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

<input type="date"/> breaks when adding bind="@model.name"

Open CanYouProgram opened this issue 8 years ago • 4 comments

            <div class="formCont1">
                <input type="date" />   
            </div>

This shows a datepicker with native styling from the browser,

If i make it
<input type="date" bind="@ath.EmailAddres"/> the date picker becomes unusable, in firefox it simply keeps resetting the type to text and in chrome it resets the value to mm/dd/yyyy everytime you pick a date. Strange

CanYouProgram avatar May 22 '18 13:05 CanYouProgram

So this is weird, if my model property is type datetime, it does not work. If i change my model type to string, it will work.

CanYouProgram avatar May 22 '18 14:05 CanYouProgram

<input type=date> requires the bound value to be of the format yyyy-MM-dd. You can use the format-value attribute to control this. Example: https://github.com/aspnet/samples/blob/master/samples/aspnetcore/blazor/FlightFinder/FlightFinder.Client/Components/Search.cshtml#L28

SteveSandersonMS avatar May 22 '18 14:05 SteveSandersonMS

For anyone late to the party, format- attributes are no longer supported. In this case, the solution is @bind:format

<input type="date" @bind="WeatherForecast.Date" @bind:format="yyyy-MM-dd" />

dapperdandev avatar Aug 08 '19 00:08 dapperdandev

Note that in preview 8 (releasing soon) this will also just work for a date field without specifying a format at all.

rynowak avatar Aug 08 '19 16:08 rynowak