Bug 242063 - Resetting the value of an input file to null should make it invalid
Summary: Resetting the value of an input file to null should make it invalid
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari 15
Hardware: Mac (Intel) macOS 12
: P2 Minor
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-06-28 09:40 PDT by Felipe Ambrosio
Modified: 2023-02-22 11:48 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felipe Ambrosio 2022-06-28 09:40:14 PDT
I'm trying to select an input[type="file"]:invalid but it doesn't work on Safari. 

That's because Safari doesn't mark it as invalid when this FormElement value is reset to "" or null.

Isolated preview: https://codepen.io/FelipePS/pen/OJvJmoK

How to reproduce error:
1) On load, input is invalid (background-color light blue) because it's empty and required.
2) Add a file to it. It changes to valid as expected, assuming background-color light grey.
3) Click "Remove file" to reset the input.

Expected behaviour: Upon clicking "Remove file", it should assume background-color light blue again, because it's now empty and it's a required field. Chrome 102 and Firefox 100 behave as expected.

Current behaviour: Safari maintains the input field as valid (background-color light grey).
Comment 1 Felipe Ambrosio 2022-06-28 09:50:26 PDT
Found a simple workaround! call setCustomValidity(" ") with a non-empty string to manually make field invalid.
Comment 2 Radar WebKit Bug Importer 2022-07-05 09:41:13 PDT
<rdar://problem/96446732>
Comment 4 Ahmad Saleem 2023-02-19 11:31:06 PST
PR - https://github.com/WebKit/WebKit/pull/10349
Comment 5 EWS 2023-02-22 11:48:54 PST
Committed 260688@main (ea06eb38955a): <https://commits.webkit.org/260688@main>

Reviewed commits have been landed. Closing PR #10349 and removing active labels.