Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML-5 date field shows as "mm/dd/yyyy" in Chrome, even when valid date is set
    primarykey
    data
    text
    <p>I just upgraded an ASP.Net MVC application to MVC-4. The field editor for inputs based on DateTime values now include's the HTML-5 <code>type="date"</code> attribute/value declaration.</p> <p>Now, when viewing in Chrome, my date inputs show up with "mm/dd/yyyy" in the input field:</p> <p><img src="https://i.stack.imgur.com/Ea0zc.jpg" alt="date field with &#39;mm/dd/yyyy&#39; in box"></p> <p>Even when I pass in a correctly-formatted date with the value attribute: </p> <pre><code>&lt;input value="2012/10/02" type="date"/&gt; </code></pre> <p>I'm still getting "mm/dd/yyyy" in the input box, which is there until the user manually changes the value.</p> <p>The problem appears to be with Chrome, and is independent of my back-end framework. See this problem in action: <a href="http://jsfiddle.net/HudMe/1/" rel="noreferrer">jsFiddle</a></p> <p>...big problem for editing records, of course. If the user pulls up a record that already has a valid date, it won't pass validation on submit, unless s/he clicked into the field and reset the value manually.</p> <p>No problems with the other browsers.</p> <p><strong>Is this a Chrome bug? Or have I missed something about the way the HTML-5 date field is supposed to work?</strong></p> <p><strong>UPDATE</strong><br> See this revise fiddle: <a href="http://jsfiddle.net/HudMe/5/" rel="noreferrer">http://jsfiddle.net/HudMe/5/</a> It has both an HTML-4 and an HTML-5 date input, each with "10/01/2012" set as the value on page-load.</p> <p>Click into either date field. The Javascript should pup up an alert with the value of the field for that element. </p> <p>Because a valid date has been passed in with the value attribute, this should show "10/01/2012", but in Chrome, for the HTML-5 date field, nothing shows. Reset this value by hand, then click again, and it will now show. </p> <p>The value from the HTML5 field shows and alerts as expected without adjustment after pageload in Safari, Firefox, IE and Opera.</p> <p><strong>Note on accepted answer:</strong><br> For other users of Asp.net mvc-4, you can adjust the display format with the <code>[DisplayFormat]</code> attribute on the DateTime field declaration in your view-model. (found at <a href="https://stackoverflow.com/a/12634470/613004">https://stackoverflow.com/a/12634470/613004</a> )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload