Bug 261432

Summary: Form associated ElementInternals always reports customError when using setValidity
Product: WebKit Reporter: Elizabeth Mitchell <lizmitchell>
Component: FormsAssignee: Alexey Shvayka <ashvayka>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, akeerthi, ashvayka, cdumez, j.graseec, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari 16   
Hardware: Mac (Apple Silicon)   
OS: macOS 13   
URL: https://jsbin.com/nodibatala/edit?html,output

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