3

Closed

input type="date" not in correct format

description

I just ran across this issue today in Chrome. If you create a page with the following

Model:
public class Model {
    [DataType(DataType.Date)]
    public DateTime LastModified { get; set; }
}
Page:
@Html.EditorFor(x => x.LastModified)
Generates This:
<input type="date" value="01/01/2001" />
However the specs require an RFC 3339 / ISO 8601 Date. The Chrome browser refuses to use the date in this format. Here is the line to the spec.

http://dev.w3.org/html5/markup/datatypes.html#form.data.date

In order to get this to work in MVC4 I have to use the following:
@Html.TextBox(
    name: "LastModified"
    value: Model.LastModified.ToString("yyyy-MM-dd"),
    htmlAttributes: new { type="date" })
Closed Jun 5, 2013 at 11:21 PM by kenegozi

comments

gldmelo wrote May 14, 2013 at 10:46 PM

This bug is giving me a lot of headaches. Please fix it soon.

yishaigalatzer wrote Jun 5, 2013 at 10:50 PM

looks the same like 630.

kenegozi wrote Jun 5, 2013 at 11:13 PM

This is a duplicate of 630 indeed.

@gldmelo, please take a look at the fix - https://aspnetwebstack.codeplex.com/SourceControl/changeset/5653d5947ede308f068a49b389e3a03b519cbc01
specifically the file test/System.Web.Mvc.Test/Html/Test/DefaultEditorTemplatesTest.cs, lines 682-693 that demonstrate the older, and the (optional) new way of rendering input-date tags.