Processing
 

'Invalid value' when setting default value in HTML5 datetime-local input

09/10/2013 22:54#1

doremi

Member

Joined at: 12 months ago

Post: 2

Thank: 0

Thanked: 0

Can someone explain why when I set the default value of a datetime-local input with seconds other than :00, the browser gives me an error of "Invalid value."?

This may be a bug in Chrome's implementation of datetime-local since this bug does not appear in the latest Firefox and Safari.

Error in Chrome: 30.0.1599.69

Invalid value when setting default value in HTML5 datetime-local input

Chrome Canary: 32.0.1665.2 canary

Invalid value when setting default value in HTML5 datetime-local input

This works:

<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:00"> 

But this does not:

<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15"> 

Link to fiddle.

Per the W3 Spec for the datetime-local input element, the value attribute should contain "A string representing a local date and time."

Example: 1985-04-12T23:20:50.52 1996-12-19T16:39:57 

I tried both of the above examples and they don't work either.

Update: Confirmed Bug & Solution

This behavior is a known bug.

As of today, the quick fix is to add the step attribute like so for non-zero seconds:

<input type="datetime-local"         name="pub_date"         value="2013-10-09T15:38:15"         step="1"> 
23/09/2015 20:34Top#2

KBall

Member

Joined at: 12 months ago

Post: 3

Thank: 0

Thanked: 0

Chrome is looking for a complete Time Stamp there is really no way around putting one. Just zero out your milliseconds and you should be good.

08/07/2016 13:33Top#3

Mayank N

Member

Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

Chrome browser require date in "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS" format. So when we assign Date and Time, we need to assign it in required format otherwise it won't show the Date Time. Even we can confirm from browser inspector tool [Ctrl+I] in console tab.

Similar articles

Chrome, THREE.js: Cross-origin image load denied

5 years ago - Reply: 5 - Views: 271

Prevent Google Chrome Log XMLHttpRequest

3 years ago - Reply: 5 - Views: 277

How can I include ChromeDriver in a JAR?

3 years ago - Reply: 3 - Views: 83

Chrome geolocation not working on any site

3 years ago - Reply: 1 - Views: 49

wrong borders' width in android browser

3 years ago - Reply: 4 - Views: 207

Uncaught SyntaxError: Unexpected token < On Chrome

3 years ago - Reply: 10 - Views: 472

Flashdata not getting cleared in Codeigniter

4 years ago - Reply: 5 - Views: 58

Illegal access Javascript error in Chrome

3 years ago - Reply: 1 - Views: 53

ng-repeat not updating in Chrome

3 years ago - Reply: 1 - Views: 82

Applying border to a checkbox in Chrome

4 years ago - Reply: 2 - Views: 119

open browser plugin using access vba

3 years ago - Reply: 1 - Views: 26

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re