Emitting Events (Global, parent, child)

Learn how to emit custom events to all open widgets, parent widget or child widgets


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 so as to perform specific operations. Note that such events are handled within the same browser application. A JSON structure can be passed to the subscriber along with the event.

Example: You need to fetch and reload data in a widget, UI Repeater, or any other component, OR you want to open or close the dialog box after an operation is performed or completed.

Steps:

1. Emitting global events:

When an event is intended to be received by any open widget in the application, emit it by giving the event name as the first argument and JSON structure to be passed as the second argument as follows:

app.emitEvent("clearpost", data.post);

2. Emitting event only to the parent widgets:

When no widget other than own parent widgets or parents of the parent should receive an event, emit an event from the component itself as follows:

source.component.emitEvent("refreshpost", params);

Emit an event from a custom UI control method as follows:

editpost(postid) { this.emitEvent("editpost", postid); },

3. Emitting event only to the child widgets:

When an event is intended only for children, emit the same as follows:

source.component.emitEventToChildren("refreshstatus", eventData);