Open Bug 1749427 Opened 4 years ago Updated 1 year ago

Decreasing value of input type time and max defined with JavaScript stepDown does not yield the expected value

Categories

(Core :: DOM: Forms, defect)

Firefox 95
defect

Tracking

()

People

(Reporter: bugzilla, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0

Steps to reproduce:

Consider the following html:

<input type="time" min="17:00" step="900" />

and call stepUp, it will set the value the first time to 17:00, then the second time to 17:15, etc. However, the other way around is not true, i.e.

 <input type="time" max="17:00" step="900" />

Then a call to stepDown will not yield the value 17:00, but instead 23:45, the second call will set the value to 17:00 and the third call will set the value to 16:45.

Actual results:

let input1 = document.createElement('input');
input1.setAttribute('type', 'time');
input1.setAttribute('min', '17:00');
input1.setAttribute('step', 900);
input1.value; // ""
input1.stepUp();
input1.value; // "17:00"
// However
let input2 = document.createElement('input');
input2.setAttribute('type', 'time');
input2.setAttribute('max', '17:00');
input2.setAttribute('step', 900);
input2.value; // ""
input2.stepDown();
input2.value; // "23:45"
input2.stepDown();
input2.value; // "17:00"
input2.stepDown();
input2.value; // "16:45"

Expected results:

I think calling stepDown on an input with a max HTML attribute defined should do like calling stepUp on an input with min HTML attribute defined, i.e. set the value to the baseline (min or max).

The Bugbug bot thinks this bug should belong to the 'Core::Layout: Form Controls' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Layout: Form Controls
Product: Firefox → Core

The severity field is not set for this bug.
:emilio, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(emilio)
Component: Layout: Form Controls → DOM: Forms
Flags: needinfo?(emilio)

The severity field is not set for this bug.
:peterv, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(peterv)
Severity: -- → S3
Flags: needinfo?(peterv)
Status: UNCONFIRMED → NEW
Ever confirmed: true

For <input type=time max=17:00 step=900> and stepDown, Blink sets the value to 0:00 while we compute 23:45. The spec is slightly ambiguous here.

What is happening is that in Gecko GetValueIfStepped / spec stepDown, value is empty and thus taken as zero. We subtract 15 minutes, value becomes negative and thus less than the maximum (see step 9). In step 11 / ConvertNumberToString, we then have to return a valid time string that represents the time that is input milliseconds after midnight on a day with no time changes.

So the problem boils down to whether "negative 15 minutes after midnight" is midnight or 23:45 of the previous day.

We can get the same issue also with stepUp and <input type=time min=17:00 value=23:45 step=900>

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: