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 undefined methods 'addClass' and removeClass on a PrototypeJS Element #22560

Conversation

markvds
Copy link
Member

@markvds markvds commented Apr 30, 2019

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); and panel.removeClass(activePanelClass);. Both methods do not exist in PrototypeJS and should have been addClassName() and removeClassName() 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)

  1. Uncaught TypeError: panel.addClass is not a function when Swatches are disabled #20843: Uncaught TypeError: panel.addClass is not a function when Swatches are disabled

Manual testing scenarios

  1. Disable Swatches modules (otherwise, the mentioned phtml file will not be used)
  2. In admin, go to Stores > Attributes > Product
  3. Click any attribute
  4. Try to save the attribute
  5. Nothing happens without the code change, but the attribute saves fine with the code change

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@m2-assistant
Copy link

m2-assistant bot commented Apr 30, 2019

Hi @markvds. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Apr 30, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@orlangur orlangur left a 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 😉

@ghost ghost assigned orlangur Apr 30, 2019
@markvds
Copy link
Member Author

markvds commented Apr 30, 2019

@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.

@orlangur
Copy link
Contributor

@markvds we don't need to add any new PrototypeJS-related code. Feel free to refactor any additional occurrences in file with jQuery.

@barryvdh
Copy link
Contributor

barryvdh commented May 1, 2019

@markvds Thank you for your PR.

@orlangur I would keep the bugfix PR as minimal as possible to make it clear what the intent and actual fix of this PR is. Also to make it easier to avoid merge conflicts etc.Refactoring the prototype should happen in a seperate PR imho.

@orlangur
Copy link
Contributor

orlangur commented May 1, 2019

@barryvdh it will be minimal as I suggested since jQuery is already injected.

@markvds please apply necessary changes.

@jissereitsma
Copy link
Contributor

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.

Copy link
Contributor

@orlangur orlangur left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
panel.addClassName(activePanelClass);
jQuery(panel).addClass(activePanelClass);

Copy link
Contributor

@orlangur orlangur left a 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 😉

@jissereitsma
Copy link
Contributor

@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.
@markvds markvds force-pushed the pr-attribute-edit-addclassname branch from e5e7254 to 1abadb5 Compare May 2, 2019 09:53
@markvds
Copy link
Member Author

markvds commented May 2, 2019

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!

@orlangur
Copy link
Contributor

orlangur commented May 2, 2019

@markvds yep, sorry for confusion, will try to formulate better next time 🤝

@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-5020 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@markvds thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@soleksii
Copy link

soleksii commented May 3, 2019

✔️ QA Passed

Before:

before

After:
after

@m2-assistant
Copy link

m2-assistant bot commented May 10, 2019

Hi @markvds, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

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

Successfully merging this pull request may close these issues.

8 participants