Closed lindapaiste closed 1 month ago
I looked into the source code and the reason that this is happening is due to some special handling in the p5.prototype._wrapElement
function, where if every child of the element is an <input>
it will call createRadio
.
It's supposed to use the p5.Element as the container for the radio, but that only works if the element is a <span>
or <div>
and does not work here because the element is a <form>
.
So the createRadio
function creates a new div
element and sets it as the .elt
.
This means that calling select('form')
when all of the form children are input
will return a p5.Element
with reference to this new empty <div>
and no reference to the actual <form>
element . Trying to use this p5.Element
will not work as intended, because it is not the right element.
The simplest fix here is that the portion of the code which conditionally calls createRadio
should also check if the element is able to be a radio parent element. That is, && (elt instanceof HTMLDivElement || elt instanceof HTMLSpanElement)
.
Most appropriate sub-area of p5.js?
p5.js version
1.9.1
Web browser and version
No response
Operating system
Windows 10
Steps to reproduce this
Steps:
<form>
element in the HTML.form = select('form')
.p5.Element
withconsole.log(form.elt)
.<div></div>
??This previously worked correctly using v0.9.0 of the standalone
p5.dom
package. I wondered if it was an intentional change that you can no longer select by tag name, but the documentation says that "The string can be an ID, class, tag name, or a combination" and includes an example withselect('canvas')
.Snippet:
https://editor.p5js.org/lindapaiste2/sketches/QX6xg14AC