@optionfactory/fml 9.0.0-rc20 → 9.0.0-rc21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ful.mjs CHANGED
@@ -1326,6 +1326,17 @@ class FormLoader {
1326
1326
  }
1327
1327
  }
1328
1328
 
1329
+ /**
1330
+ * The form owning an element: its `form` property, or `internals.form` for a
1331
+ * form-associated element that has none. An element no form can own answers
1332
+ * undefined, its internals, which every ParsedElement holds, throwing on a
1333
+ * read of `form` unless the element is form-associated.
1334
+ * @param {any} el
1335
+ * @returns {HTMLFormElement|null|undefined}
1336
+ */
1337
+ const ownerOf = (el) =>
1338
+ el.form !== undefined ? el.form : el.constructor?.formAssociated ? el.internals?.form : undefined;
1339
+
1329
1340
  /**
1330
1341
  * Moves its children into a native `<form novalidate>`, extracts their values
1331
1342
  * on submit and hands them to a loader, reporting problems through `errors`.
@@ -1391,7 +1402,7 @@ class Form extends ParsedElement {
1391
1402
  );
1392
1403
  if (this.declared('clear-invalid-on-change')) {
1393
1404
  this.addEventListener('change', (/** @type any */ evt) => {
1394
- if ((evt.target.form ?? evt.target.internals?.form) !== this.form) {
1405
+ if (ownerOf(evt.target) !== this.form) {
1395
1406
  return;
1396
1407
  }
1397
1408
  evt.target.setCustomValidity?.('');
@@ -1622,7 +1633,7 @@ class Form extends ParsedElement {
1622
1633
  */
1623
1634
  #nameOf(target) {
1624
1635
  for (let el = target; el && el !== this; el = el.parentElement) {
1625
- if ((el.form ?? el.internals?.form) === this.form && el.hasAttribute('name')) {
1636
+ if (ownerOf(el) === this.form && el.hasAttribute('name')) {
1626
1637
  return el.getAttribute('name');
1627
1638
  }
1628
1639
  }