Skip to content

Issue #30594 - added preventDefault if EventListner is added for a tag #30628

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

Open
wants to merge 9 commits into
base: 2.4-develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ function {$listenerFunction} () {
targetElement = event.target;
}
{$listenerFunction}.apply(targetElement);
}
if ({$elementName}.nodeName == 'A' && "$eventName" == 'onclick') {
event.preventDefault();
}
}
}

script;

return $this->renderTag('script', ['type' => 'text/javascript'], $script, false);
Copy link
Contributor

@mrtuvn mrtuvn Nov 25, 2020

Choose a reason for hiding this comment

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

Hard-code logic check nodename is not good way. IMO
You should add change method _toLinkHtml in https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Action.php#L143
CC: @rogyar @zaximus84

Copy link
Contributor

Choose a reason for hiding this comment

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

Example
Screenshot from 2020-11-26 06-57-55

Copy link
Author

@amitsamsukha amitsamsukha Dec 2, 2020

Choose a reason for hiding this comment

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

@mrtuvn
thanks for the suggestion, but the preventDefault only works if called within function onclick into:

https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Helper/SecureHtmlRenderer.php#L116

the issue is resolved by just adding onclick if condition but I have put a double-check for the anchor tag.
let me know if I need to remove the anchor tag check in this.
CC: @rogyar @zaximus84

Expand Down