1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibWeb: Reset form association when any element with an ID changes

When an element with an ID is added to or removed from the DOM, or if
an ID is added, removed, or changed, then we must reset the form owner
of all form-associated elements who have a form attribute.

We do this in 2 steps, using the DOM document as the messenger to handle
these changes:

1. All form-associated elements with a form attribute are stored on the
   document. If the form attribute is removed, the element is removed
   from that list as well.

2. When a DOM element with an ID undergoes any of the aforementioned
   changes, it notifies the document of the change. The document then
   forwards that change to the stored form-associated elements.
This commit is contained in:
Timothy Flynn 2024-02-03 10:29:26 -05:00 committed by Andrew Kaster
parent 960dcf0e56
commit a17074422e
8 changed files with 97 additions and 6 deletions

View file

@ -63,6 +63,9 @@
<form id="changeForFormAttribute"></form>
<input id="changeForFormAttributeInput" type="text" name="changeForFormAttribute" />
<input id="inputBeforeForm" type="text" form="formAfterInput" />
<form id="formAfterInput"></form>
<script src="../include.js"></script>
<script>
test(() => {
@ -138,5 +141,10 @@
changeForFormAttributeInput.removeAttribute("form");
println(`elements in changeForFormAttribute: ${changeForFormAttribute.elements.length}`);
println("== Form element appears after a form-associated element ==");
let formAfterInput = document.getElementById("formAfterInput");
println(`elements in formAfterInput: ${formAfterInput.elements.length}`);
println(`typeof formAfterInput.inputBeforeForm: ${typeof formAfterInput.inputBeforeForm}`);
});
</script>