Skip to content

Commit fd186f8

Browse files
authored
Merge pull request #7162 from Forchapeatl/patch-1
Fix: Added unique group names for radio buttions
2 parents cc17b64 + 5729faf commit fd186f8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/dom/dom.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,9 @@ p5.prototype.createSelect = function(...args) {
15801580
* @method createRadio
15811581
* @return {p5.Element} new <a href="#/p5.Element">p5.Element</a> object.
15821582
*/
1583+
1584+
//counter for unique names on radio button
1585+
let counter = 0;
15831586
p5.prototype.createRadio = function(...args) {
15841587
// Creates a div, adds each option as an individual input inside it.
15851588
// If already given with a containerEl, will search for all input[radio]
@@ -1611,8 +1614,9 @@ p5.prototype.createRadio = function(...args) {
16111614
self = addElement(radioElement, this);
16121615
this.elt = radioElement;
16131616
}
1614-
self._name = name || 'radioOption';
16151617

1618+
// Generate a unique name for each radio group if not provided
1619+
self._name = name || `radioOption_${counter++}`;
16161620
// setup member functions
16171621
const isRadioInput = el =>
16181622
el instanceof HTMLInputElement && el.type === 'radio';

0 commit comments

Comments
 (0)