Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Added unique group names for radio buttions #7162

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

Forchapeatl
Copy link
Contributor

@Forchapeatl Forchapeatl commented Aug 8, 2024

This PR ensures unique names for each radio button group in createRadio function
Resolves #6763

Resolves #6763

Changes:

  • Added a Counter for Unique Radio button Names
  • Modified the self._name Assignment

Screenshots of the change:

Apex_1723102309099.mp4

PR Checklist

Copy link

welcome bot commented Aug 8, 2024

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@Forchapeatl Forchapeatl marked this pull request as ready for review August 8, 2024 07:49
src/dom/dom.js Outdated
@@ -1738,6 +1723,10 @@ p5.prototype.createRadio = function(...args) {
return self;
};

// Initialize counter for unique radio group names
p5.prototype.createRadio.counter = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if p5's prototype is a good place to keep this counter, although I am not much aware of the code base to provide an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the review , please where is the prototype class . I will be happy to keep the counter there. I am still learning the structure of the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we are not adding anything new to the prototype of p5 ... we are adding to createRadio which is already there, so I guess this can be OK, you can ignore my previous comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure attaching to createRadio as a property is a good idea here. If it is just something that is kept tracked of internally, it can just be a scoped variable, ie. let counter = 0.

Copy link
Contributor Author

@Forchapeatl Forchapeatl Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use let counter = 0 within the function’s scope, the counter resets with each call to createRadio, and causes duplicate names like radioOption_0 for multiple radio groups. When I attach the counter to p5.prototype.createRadio, each group gets a unique identifier ( radioOption_1, radioOption_2), avoiding conflicts between radio groups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The let statement should be outside of the function scope, it can be in the file scope as the bundler won't leak file level local variable to the larger environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have made the changes with the global counter.

@Forchapeatl Forchapeatl changed the title unique group names for radio buttions Fix: Added unique group names for radio buttions Aug 11, 2024
@limzykenneth
Copy link
Member

I see many of the existing code comments are removed, is there a reason for that?

@Forchapeatl
Copy link
Contributor Author

Forchapeatl commented Aug 22, 2024

I see many of the existing code comments are removed, is there a reason for that?

I have placed back the comments

@limzykenneth limzykenneth merged commit fd186f8 into processing:main Aug 22, 2024
2 checks passed
@limzykenneth
Copy link
Member

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Radio buttons interact with each other
3 participants