Skip to content

Commit

Permalink
Merge pull request #7162 from Forchapeatl/patch-1
Browse files Browse the repository at this point in the history
Fix: Added unique group names for radio buttions
  • Loading branch information
limzykenneth authored Aug 22, 2024
2 parents cc17b64 + 5729faf commit fd186f8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,9 @@ p5.prototype.createSelect = function(...args) {
* @method createRadio
* @return {p5.Element} new <a href="#/p5.Element">p5.Element</a> object.
*/

//counter for unique names on radio button
let counter = 0;
p5.prototype.createRadio = function(...args) {
// Creates a div, adds each option as an individual input inside it.
// If already given with a containerEl, will search for all input[radio]
Expand Down Expand Up @@ -1611,8 +1614,9 @@ p5.prototype.createRadio = function(...args) {
self = addElement(radioElement, this);
this.elt = radioElement;
}
self._name = name || 'radioOption';

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

0 comments on commit fd186f8

Please sign in to comment.