Reputation: 4730
Using the datetime-local input type on Chrome doesn't seem to work when the value is set via Javascript and the value contains seconds. Why is this happening? It seems to be a general thing. In simple terms, here's how to re-create the problem:
input
element with type='datetime-local'
..value
) with a non-zero seconds (eg. '1980-01-01T01:01:01.001'
) value.But, if you set the seconds to 0 (eg. 1980-01-01T01:01:00.001
), or the value is set via HTML attributes, then the validation error doesn't get thrown and the form submits fine.
See this CodePen sample: http://codepen.io/AskYous/pen/KNONVG
Upvotes: 2
Views: 2058
Reputation: 6150
It's an expected behavior defined by the HTML standard.
The default step
value for type=datetime-local
is 1 minute. The default step-base is Unix epoch 1970-01-01T00:00:00. So 1980-01-01T01:01:01.001
causes a step-mismatch validation error.
If min
attribute or value
attribute is specified, it would be the step-base.
Upvotes: 1
Reputation: 4730
It seems it's a bug in Chrome. I found a solution. Use the .setAttribute()
function:
datetimeInput.setAttribute('value', '1980-01-01T01:01:01.001');
Upvotes: 1