I have an Angular project, where one of the components have an input time like:
<div class="start">
<p>Inicio:</p>
<input type="time" class="form-control"/>
</div>
It is possible to set a range in the minutes of the input? I mean, when I have to choose an hour in this input, I need to choose an hour and a minute. I want the possibility of visualize only the minute 00 and the minute 30, instead of all the minutes 00, 01, 02, 03…59
2
Answers
What you’re describing isn’t really a "range" – what you want is to set the resolution of the input to 30 minutes, instead of 1 minute.
And you can do that with the
step=""
attribute. Fortype="time"
thestep=""
attribute’s unit is seconds, so 30 minutes is 1,800 seconds:…however, none of the major browsers seem to support the
step=""
attribute withtype="time"
yet (using Chrome 117, it encounters a step mismatch, which means Chrome internally supports thestep
attribute, but doesn’t constrain the time-picker UI tostep
).Reasonable alternatives:
Something like this, I guess:
So the bottom line is, it is a built in browser feature and no attributes available to alter the formatting.
Moreover,
step=""
attribute only works for keyboard up-down arrows but doesn’t work when selecting the time using mouse.Now as per your scenario, as you have mentioned that it is an Angular project and you want to use minute field which will contain only 00 and 30, it can be achieved in several ways.