-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 undefined methods 'addClass' and removeClass
on a PrototypeJS Element
#22560
Fix undefined methods 'addClass' and removeClass
on a PrototypeJS Element
#22560
Conversation
Hi @markvds. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markvds please use jQuery
equivalents instead.
After changes are applied and all builds are green, please squash them into a single commit so that we have perfectly clean history 😉
@orlangur I cannot imagine that it makes the situation any better; it's all surrounded by PrototypeJS code. I think it would even make readibility worse. |
@markvds we don't need to add any new PrototypeJS-related code. Feel free to refactor any additional occurrences in file with jQuery. |
My 50 cents: The proposed fix of @markvds is a bugfix. However, the suggestion of @orlangur would lead to a code enhancement. They are different things. I'm not sure if postponing the bugfix is a good idea, waiting for the code enhancement. On the other hand, I'm not sure how much work the refactoring the jQuery code would be. Just my 50 cents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial code was jQuery-style. There is no need to step back. Please replace all addClassName/removeClassName
.
@@ -45,11 +45,11 @@ function checkOptionsPanelVisibility(){ | |||
|
|||
if($('frontend_input') && ($('frontend_input').value=='select' || $('frontend_input').value=='multiselect')){ | |||
panel.show(); | |||
panel.addClass(activePanelClass); | |||
panel.addClassName(activePanelClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panel.addClassName(activePanelClass); | |
jQuery(panel).addClass(activePanelClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After changes are applied and all builds are green, please squash them into a single commit so that we have perfectly clean history 😉
@orlangur You are awesome |
…lement The code was originally copied from the Swatches module, which already uses jQuery. In this file however, the 'panel' variable is not a jQuery object but a DOM Element.
e5e7254
to
1abadb5
Compare
I changed the PR. @orlangur I finally get your point. You basically say the method name was correct, but the context was wrong. I assumed the context was right but the method name was wrong. It's just a different view on the situation. Understanding your thoughts helps me in future PRs. Thanks for explaining! |
@markvds yep, sorry for confusion, will try to formulate better next time 🤝 |
Hi @orlangur, thank you for the review. |
…PrototypeJS Element magento#22560
Hi @markvds, thank you for your contribution! |
Description
This problem was caused by 5a283e3 and reported in #20843. The mentioned commit adds two lines in
js.phtml
with non existing methods:panel.addClass(activePanelClass);
andpanel.removeClass(activePanelClass);
. Both methods do not exist in PrototypeJS and should have beenaddClassName()
andremoveClassName()
respectively.The incorrect method names cause a Javascript error 'Uncaught TypeError: panel.addClass is not a function' in the console and prevents the Edit Attribute form from saving.
Enabling the Swatches module, as mentioned in the issue, only solves the issue because it replaces the phtml file with its own file.
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist