Emitting Events (Broadcast, global, parent, child)
Learn how to emit custom events to all open widgets, parent widget, or child widgets.
Custom Event Emission in UI Components
When the standard events exposed by various UI components such as On Click or On Mouse Over do not suffice, custom events can be emitted from within client-side scripts, custom UI scripts, or custom UI controls to perform specific operations.
These events are handled within the same browser application. A JSON structure can also be passed to the subscriber along with the event.
Example Use Cases
Fetch and reload data in a widget, UI Repeater, or any other component.
Open or close a dialog box after an operation is performed or completed.
Steps
1. Emitting Broadcast Events
When an event needs to be notified to all users currently using the application, emit it by passing the application name as the first argument and the event name as the second argument:
sendMessage("P;tasks/*;REFRESH");
2. Emitting Global Events
When an event is intended to be received by any open widget in the application, emit it by providing the event name as the first argument and the JSON structure as the second:
app.emitEvent("clearpost", data.post);
3. Emitting Events Only to Parent Widgets
When you want to ensure that only the parent widgets (or their parents) receive the event, emit it from the component:
source.component.emitEvent("refreshpost", params);
You can also emit an event from a custom UI control method like so:
editpost(postid) {
this.emitEvent("editpost", postid);
},
4. Emitting Events Only to Child Widgets
To send an event that should only be received by child widgets, use the following syntax:
source.component.emitEventToChildren("refreshstatus", eventData);