Bug 261432 - Form associated ElementInternals always reports customError when using setValidity
Summary: Form associated ElementInternals always reports customError when using setVal...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari 16
Hardware: Mac (Apple Silicon) macOS 13
: P2 Normal
Assignee: Alexey Shvayka
URL: https://jsbin.com/nodibatala/edit?htm...
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-09-11 14:42 PDT by Elizabeth Mitchell
Modified: 2023-12-18 05:53 PST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elizabeth Mitchell 2023-09-11 14:42:36 PDT
A form associated custom element can call `internals.setValidity(flags)`. If `customError` is missing or set to `false` in the flags, `internals.validity.customError` always reports true, as long as one of the validity flags is set to true.

```
<script>
  class XControl extends HTMLElement {
    static formAssociated = true;
  
    constructor() {
      super();
      this.internals = this.attachInternals();
      this.internals.setValidity({valueMissing: true, customError: false}, 'Value missing');
      // Expecting "customError: false"
      alert(`customError: ${this.internals.validity.customError}`);
    }
  }
  
  customElements.define('x-control', XControl);
</script>
<x-control></x-control>
```

Repro: https://jsbin.com/nodibatala/edit?html,output

Expectation: open the repro and get an alert of "customError: false". This works in Chrome and Firefox

Actual: Safari 16.6 reports "customError: true", even when customError is set to false.
Comment 1 Ahmad Saleem 2023-09-12 12:47:45 PDT
I am able to reproduce this bug in WebKit ToT (267909@main) and get `customError: true` while Firefox Nightly 118 and Chrome Canary 118 get `customError: false`.
Comment 2 Ahmad Saleem 2023-09-12 13:02:20 PDT
Might be reseting validity here: https://searchfox.org/wubkat/source/Source/WebCore/html/FormListedElement.cpp#266

by using validityCheck(); ?
Comment 3 Radar WebKit Bug Importer 2023-09-18 14:57:47 PDT
<rdar://problem/115681066>
Comment 4 Alexey Shvayka 2023-10-23 11:40:12 PDT
Pull request: https://github.com/WebKit/WebKit/pull/19434