Ali Samie Posted August 9, 2022 Share Posted August 9, 2022 (edited) I have searched and come up with these two: DisplayAdditionalCustomerAddressFields ActionCheckoutRender I think it is better to use: ActionFrontControllerSetMedia Because this way we can ensure libraries like jquery are loaded before loading any other library or code and just set an if clause to let it load the js file where you need it Any other ideas? Edited January 22, 2023 by Ali Samie (see edit history) Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted August 22, 2022 Share Posted August 22, 2022 Hi.. Read this link if something help for your point https://devdocs.prestashop.com/1.7/themes/reference/javascript-events/ Thank you Link to comment Share on other sites More sharing options...
Ali Samie Posted August 25, 2022 Author Share Posted August 25, 2022 Hi. I just take a look and did not understand the relation to my question that much. I see there are two headers with these titles: 1. Dispatch an event 2. Listening to events My question is how to trigger a custom defined event? Link to comment Share on other sites More sharing options...
knacky Posted August 25, 2022 Share Posted August 25, 2022 https://www.google.com/amp/s/attacomsian.com/blog/javascript-dom-trigger-built-in-and-custom-events%3famp 1 Link to comment Share on other sites More sharing options...
Ali Samie Posted August 25, 2022 Author Share Posted August 25, 2022 30 minutes ago, knacky said: https://www.google.com/amp/s/attacomsian.com/blog/javascript-dom-trigger-built-in-and-custom-events%3famp Thanks for this. I checked this and did not quite understand what it means. When I was looking prestashop documents, I saw this on how to dispatch new event (?) prestashop.emit( 'myEventName', { myData1: 1, myData2: 3 } ); Then furthermore in the article I found this on how to define an event listener: if (typeof prestashop !== 'undefined') { prestashop.on( 'myEventName', function (event) { var eventDatas = {}; if (event && event.reason) { eventDatas = { my_data_1: event.reason.myData1, my_data_2: event.reason.myData2 }; } } ); } My question is how to trigger this event? I checked the link that you have shared and tried this: prestashop.dispatchEvent('myEventName'); But it does not work and gives me this error: Uncaught TypeError: prestashop.dispatchEvent is not a function Link to comment Share on other sites More sharing options...
Ali Samie Posted August 25, 2022 Author Share Posted August 25, 2022 well, it seems that I am really a noob when it comes to javascript.😅 prestashop.emit() works just like prestashop.dispatchEvent() should. Boy I wish I have never asked this silly question🤣 So to wrap things up, there are simply two steps: 1. add a event listener 2. trigger that event for step one this is an example: prestashop.on( 'myEvent', function (event) { console.log('hello') } ); for step two: prestashop.emit('myEvent'); And for the result you should see hello in console 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now