21
Views
4
Comments
Solved
Eventing from JavaScript
Question

I am building a JS library from which I need to trigger an event. Currently it is only possible to trigger an event from a webblock. How can I call a method of a web block from Javascript client action. 

mvp_badge
MVP
Rank: #96
Solution

Hello Siya, 

You will find inspiration from Firebase component,  FirebaseReciever web block. (This is using jquery) 

One approach to achieve what you need using javascript is  explained below 

Step 1: Create a web block with Events you wish to trigger 

Step 2: Implement a custom listener with a getter & setter on a javascript object. 

Step 3: In the Initialize() of the web block register for a callback 

Step 4: Set the value from your javascript when you wish to trigger the event. 

Step 5: When the callback is fired in the web block, hook it to an action in the web block that can trigger the event. 

Check this link on how to implement the custom listener.  

Hope this helps. 

Hi Siya,

If i understand question correctly, you can run the client action from javascript like below.

If you are looking to trigger event from script. Try to put that event in action and trigger that action from javascript.


Regards,

Rama

Rank: #170

Hi Siya,

Take a look at this component.

It may help you understand how to do what you want.


Cheers and Regards,

RR :)

mvp_badge
MVP
Rank: #96
Solution

Hello Siya, 

You will find inspiration from Firebase component,  FirebaseReciever web block. (This is using jquery) 

One approach to achieve what you need using javascript is  explained below 

Step 1: Create a web block with Events you wish to trigger 

Step 2: Implement a custom listener with a getter & setter on a javascript object. 

Step 3: In the Initialize() of the web block register for a callback 

Step 4: Set the value from your javascript when you wish to trigger the event. 

Step 5: When the callback is fired in the web block, hook it to an action in the web block that can trigger the event. 

Check this link on how to implement the custom listener.  

Hope this helps. 

Rank: #588

Thanks Amal. That helped.

Thanks Raphael Ranieri and Ramakrushnarao Seera for your support