Closed Bug 1613280 Opened 4 years ago Closed 3 months ago

It's possible to type a date that exceeds the value of the max attribute (input type date min max)

Categories

(Core :: DOM: Forms, defect, P3)

72 Branch
defect

Tracking

()

RESOLVED FIXED
124 Branch
Tracking Status
firefox124 --- fixed

People

(Reporter: kraig.tri125, Assigned: opensource, NeedInfo)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Attached image firefox_yVdu9yQlEY.png

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0

Steps to reproduce:

In a date input field:
1- Set the max attribute to "9999-12-31".
2- Select the year and type "1" until that part of the input is completely filled.

Actual results:

The year grows to 6 digit.

Expected results:

I expected the input to only allow 4 digits to be entered as the mask is displayed to be "yyyy-mm-dd" with 4 digits for the year.

I expected the selection to move to the month after entering 4 digits for the year.

Type: enhancement → defect
Has STR: --- → yes
Component: Untriaged → Layout: Form Controls
Product: Firefox → Core
See Also: → 1501987, 1363660
Summary: Date Input field 6 digit year → It's possible to type a date that exceeds the value of the max attribute

This sounds like the same issue described in bug 1363660 comment 3 (though it probably does deserve its own bug, i.e. this bug here).

Note that the field ordering here depends on locale. For me in my en-US Firefox build, input type="date" renders with MM-DD-YYYY, by default at least (or YYYYYY if I keep typing :) ). But I can see how this would be an issue if you had YYYY as the first part of the field.

RE step 1 of the STR -- I'm actually not sure whether the "max" attribute is supposed to have any effect on what happens when you are typing inside the field -- my recollection is that the browser is only supposed to validate the input after you've left the field, and again when you submit the form. But, I can see how on-the-fly validation (and value-constraining) would be useful from a UX perspective.

Also: according to bug 1363660 comment 3, the requested behavior here apparently is what Chrome already does. So, this is a chrome-parity UX concern, even if it's not explicitly required per spec (which I don't know for sure). Hence, marking as a confirmed bug and calling this P3 (backlog).

Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: parity-chrome
Priority: -- → P3

(adding a few words to the subject to hopefully make it easier to find)

Summary: It's possible to type a date that exceeds the value of the max attribute → It's possible to type a date that exceeds the value of the max attribute (input type date min max)

Note that we also have bug 1501987 open on a related issue - namely that the UI isn't restricted to the min/max interval.

Hey, what about that? Is there any PR I could continue or review to help?

This is not actually chromiuX :) this is just the way You written it explicitly DD/MM/YYYY if I have YYYY I require to have 4 digits.
More over - date input is not for archeologic purpose and only support modern period called AD...

So, how could we fix that?
Cheers.

Flags: needinfo?(dholbert)

...last but not least - consolidated bug ( https://bugzilla.mozilla.org/show_bug.cgi?id=1502390 ) is not looking for this bugfix imho but for feature (so there is feature request not a bug ) to better selector (UX?).

This is simply and actually very plain to fix year input & display. As YYYY is there only 4 digits should be allowed. We have time to latter refactor Guys....

(In reply to julianvolodia from comment #7)

Hey, what about that? Is there any PR I could continue or review to help?

Thanks for the offer. There's no in-progress work here that could be continued, no. This needs someone to dive into the code that runs every time a character is typed into the field, and figure out how to add the logic required for this bug. That code would probably need to live in HTMLInputElement::BeforeSetAttr / HTMLInputElement::AfterSetAttr perhaps, though I'm not really sure.

https://searchfox.org/mozilla-central/rev/fa48ebee58d59fa846919c3e2c3122b08db57c9c/dom/html/HTMLInputElement.cpp#1135
https://searchfox.org/mozilla-central/rev/fa48ebee58d59fa846919c3e2c3122b08db57c9c/dom/html/HTMLInputElement.cpp#1169

Also, this actually belongs in DOM:Forms, since that component/code is responsible for managing validity/content in form fields, whereas this layout subcomponent is more about "how big is the component and where do its pieces go". --> Reclassifying.

Component: Layout: Form Controls → DOM: Forms
Flags: needinfo?(dholbert)
Severity: normal → S3
Assignee: nobody → opensource
Status: NEW → ASSIGNED
Attachment #9367141 - Attachment description: Bug 1613280 - Change mMaxYear based on the input's max value → Bug 1613280 - Change mMaxYear to 9999 (ISO 8601)

After discussion with :emilio, :zcorpan, and :ayeddi, we've decided to only allow four digits when typing in a value for year in the datetime-local date picker. We are still able to display years greater than 9999 with the proposed changes, and one is still able to select a year greater than 9999 when using the date picker (as long as the max attribute doesn't prevent a user from selecting a year greater than 9999). The constraint validation of invalid dates and dates outside of the min and max ranges are unaffected by this change.

Additionally, Chrome and Safari both allow 6 digits to be entered in to the year part of the datetime-local input so removing the parity-chrome keyword.

Keywords: parity-chrome
Pushed by tgiles@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/51eeece91171
Change mMaxYear to 9999 (ISO 8601) r=reusable-components-reviewers,tgiles

Backed out for causing mochitest-plain failures in test_input_date_key_events.html.

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: TEST-UNEXPECTED-FAIL | dom/html/test/forms/test_input_date_key_events.html | Test with 0101275769, result should be 275760-01-01 - got "0069-01-01", expected "275760-01-01"
Flags: needinfo?(opensource)
Attachment #9367141 - Attachment description: Bug 1613280 - Change mMaxYear to 9999 (ISO 8601) → WIP: Bug 1613280 - Change mMaxYear to 9999 (ISO 8601)
Attachment #9367141 - Attachment description: WIP: Bug 1613280 - Change mMaxYear to 9999 (ISO 8601) → Bug 1613280 - Change mMaxYear to 9999 (ISO 8601)
Pushed by tgiles@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f14117e2fa1e
Change mMaxYear to 9999 (ISO 8601) r=reusable-components-reviewers,tgiles
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: