Bug 269641
Summary: | checkValidity() of input[type="date"] returns an unexpected result when an entered value is replaced by an empty string. | ||
---|---|---|---|
Product: | WebKit | Reporter: | ef81sp |
Component: | Forms | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW | ||
Severity: | Normal | CC: | akeerthi, annevk, cdumez, mike, ntim, webkit-bug-importer, wenson_hsieh |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 17 | ||
Hardware: | Mac (Apple Silicon) | ||
OS: | macOS 14 |
ef81sp
Sample on JSFiddle: https://jsfiddle.net/xL581koz/
[Summary]
- After entering a value in input[type="date"], setting an empty string "" will cause checkValidity() to return false, despite the validityState values being correct.
- So the form cannot be submit.
- No issues occur when using form reset to clear the value.
[Expected]
For the condition,
- checkValidity() returns true.
- The form can be submitted successfully.
[How to reproduce]
1. enter a valid value in the input[type="date"] of the form.
2. set an empty string ("") to the input element in JS.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/123549879>
Anne van Kesteren
I can also reproduce this for other form controls:
https://software.hixie.ch/utilities/js/live-dom-viewer/?%3Cinput%20type%3Dtime%3E%0A%3Cscript%3E%0Ainput%20%3D%20document.querySelector(%27input%27)%0Ainput.value%20%3D%20%2212%3A12%22%3B%0Ainput.value%20%3D%20%22%22%3B%0Aw(input.checkValidity())%0A%3C%2Fscript%3E
It seems that the problem is that as soon as a value is set some state gets initialized that is not reset when the value is "removed" again.
Anne van Kesteren
The problem appears to be that BaseDateAndTimeInputType::hasBadInput() starts returning true when input is set to the empty string after it's been non-empty and valid.