This topic contains 5 replies, has 2 voices, and was last updated by Stepan Yudin 7 years, 3 months ago.
- Topic
Good day everyone
I totally cannot figure out how to solve my problem.
To put it briefly: my JS function fires multiple times.I put JS handlers directly into my templates
Lets consider the following simple example.12345678910111213141516171819202122{% block content_data %}...<script type="text/javascript">require(['jquery'], function ($) {$(function () {$('body').on('click', '.my-button', function (e) {var text = $(e).text();console.log(text + ' clicked');});});});</script><a href="#" rel="nofollow">Test button</a>...{% endblock content_data %}So, each time i open this page – js handlers applies again and when i click a button i recieve several messages in console.
I understand why this happens – frontend doesnt know when to dispose my JS functions and they stay alive.What is the simplest way to solve this? Im totally dumb in modern JS frontend. I saw manual how to define components, but i dont need to define template of component. Only js handlers to intercept click on some elements with some classes.
In fact all i need is to create some click handlers (for special CSS classes) and correctly apply them only at specified pages (not across the whole application)Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
https://github.com/stepansib/sf-oro-docker
The forum ‘OroPlatform – HTML, JavaScript, CSS, Design Questions’ is closed to new topics and replies.