Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

enter image description here

Chrome Canary: 32.0.1665.2 canary

enter image description here

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"> 
like image 580
doremi Avatar asked Oct 09 '13 22:10

doremi


People also ask

Is datetime valid in HTML5?

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.

How to take datetime input in HTML?

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.


1 Answers

This works in Chrome Version 52.0.2743.116 m

<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15" /> 
like image 176
Eileen Jones Avatar answered Sep 20 '22 16:09

Eileen Jones