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
Chrome Canary: 32.0.1665.2 canary
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">
One of the new changes being introduced in HTML5 is the support for date/time as a first class input element type. The introduction of this new input type allows web developers to get the input element's value as a string which represents date/time. There are two input types supported for “datetime” like inputs. 2.
The datetime input type is used in HTML using the <input type="datetime-local">. Using this, allow the users to select date and time. A date time picker popup is visible whenever input field is clicked. Note − The input type datetime is not supported in Firefox and Internet Explorer.
This works in Chrome Version 52.0.2743.116 m
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With