Reputation: 1095
So I have the following html input like so
<input id="time_in" type="time" step="1" name="duration">
And when I set the value in browser to "00:00:00" all seems good.
But then you jump into the console (or submit the form, etc.) the value is truncated to "00:00"
i.e. jquery
$("#time_in")[0].value == "00:00"
or plain js
document.getElementById("time_in").value == "00:00"
My question is what gives? Is this supposed to be the behavior? This doesn't seem correct to me, does anyone know if I'm not setting an attribute or doing something non-standard?
edit:
if it makes any difference this is only with "00:00:00", when you set it to "00:00:01" it's correctly set and you can
document.getElementById("time_in").value == "00:00:01"
Upvotes: 2
Views: 4221
Reputation: 46208
This is standard-compliant behaviour, but so is 00:00:00
.
In the HTML5 specification:
The
value
attribute, if specified and not empty, must have a value that is a valid time string.
Where a "valid time string" is:
A string is a valid time string representing an hour
hour
, a minuteminute
, and a secondsecond
if it consists of the following components in the given order:
- Two ASCII digits, representing hour, in the range 0 ≤
hour
≤ 23- A ":" (U+003A) character
- Two ASCII digits, representing minute, in the range 0 ≤
minute
≤ 59- Optionally (required if
second
is non-zero):
- A ":" (U+003A) character
- Two ASCII digits, representing the integer part of
second
, in the range 0 ≤s
≤ 59- Optionally (required if
second
is not an integer):
- A 002E FULL STOP character (.)
- One, two, or three ASCII digits, representing the fractional part of
second
Note: The
second
component cannot be 60 or 61; leap seconds cannot be represented.
Therefore, the last bit after the minute (including the colon) is optional if the second is zero, but not prohibited.
Upvotes: 3