datetime-local supports valueAsDate when it shouldn't
Categories
(Core :: DOM: Forms, defect)
Tracking
()
People
(Reporter: opliko.reg, Assigned: ltenenbaum)
References
(Regression)
Details
(Keywords: regression)
Attachments
(1 file)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0
Steps to reproduce:
Used inputElement.valueAsDate when the input type="datetime-local"
Actual results:
It returned a Date object, making me believe the code was correct while it didn't work in browsers that followed the specification more strictly on that front
Expected results:
It should've returned null as per the specification: https://html.spec.whatwg.org/multipage/input.html#dom-input-valueasdate
"On getting, if the valueAsDate attribute does not apply, as defined for the input element's type attribute's current state, then return null."
For datetime-local: https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type=datetime-local)
"The following IDL attributes and methods do not apply to the element: checked, files, selectionStart, selectionEnd, selectionDirection, and valueAsDate IDL attributes; setRangeText(), and setSelectionRange() methods."
Relevant Chromium issue where returning null was deemed the correct behavior: https://issues.chromium.org/issues/40475290
This is a compatibility issue and it allows for browser detection. It's definitely not a major issue, but I also don't think that (especially considering lack of support for other browsers) it makes much sense leaving a footgun in a somewhat obscure API, where the intuitive usage works only in Firefox.
Also, this was tracking addition of
Comment 3•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Layout: Form Controls' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Updated•1 year ago
|
Comment 4•1 year ago
|
||
I can't reproduce this on https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13331
Reporter, do you have a minimized test case?
Apologies for taking so long to respond - but it seems your test case reproduces the issue? Tested on FF135.0b9 (desktop), FF136.0a1 (mobile), FF1340.2 (mobile) and FF Focus 134.0.2 (mobile). All give me the same result - valueAsDate returns a Date object for a fully filled out datetime-local input (note: you need to enter both the date and time to get a value there and FF only shows a date picker, requiring keyboard input for time. If you enter only the date then valueAsDate will be null, but also value will be an empty string.).
Chrome 132.0.6834.122 and Ungoogled Chromium 132.0.6834.110 both correctly return null even when both the date and time are filled for datetime-local inputs, only working with date inputs.
Comment 6•1 year ago
|
||
I think I can reproduce the difference the reporter is talking about.
- Load https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13331
- In the top date input widget, fill it out completely with
01/01/2000, 5:00 AM - Click on print, look at the text produced in the "log" section below.
In Firefox, the output is log: object "Fri Dec 31 1999 21:00:00 GMT-0800 (Pacific Standard Time)" (0 props).
In Chrome, the output is log: object "null" (0 props).
I have no idea how much of a webcompat problem this might be.
| Assignee | ||
Comment 7•24 days ago
|
||
Updated•24 days ago
|
Comment 10•17 days ago
|
||
| bugherder | ||
Updated•17 days ago
|
Comment 14•16 days ago
|
||
The patch landed in nightly and beta is affected.
:ltenenbaum, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.
- See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift.
- If no, please set
status-firefox149towontfix.
For more information, please visit BugBot documentation.
Updated•16 days ago
|
| Assignee | ||
Updated•16 days ago
|
Description
•