Skip to content

Sending events with your widgets

Custom widgets emit events through the framework adapter’s click(), valueChanged(), onLoad(), onFilter(), or onBlur() methods. Each method optionally accepts a detail payload.

this.adapter.click('twitter'); // fires the wired click event with detail = 'twitter'
this.adapter.valueChanged(newVal); // pushes a new value AND emits onChange
this.adapter.onFilter('toyota'); // emits onFilter with detail = 'toyota'

Event names are wired in the widget definition, not in the component:

gui.actions.custom('productShare', { onClick: 'shareEvent' });

When your widget calls this.adapter.click('twitter'), the engine emits an event with name: 'shareEvent' and detail: 'twitter' to the form’s formEvent callback.

The application-side handler receives a FormEvent object with the event name, the current form data, and an optional detail payload passed from the widget. In this example, productShare passes the network id (e.g. 'twitter', 'facebook', 'linkedin') as detail:

const SHARE_URLS: Record<string, (url: string) => string> = {
twitter: (url) => `https://x.com/intent/tweet?text=${encodeURIComponent('Check out this product!')}&url=${encodeURIComponent(url)}`,
facebook: (url) => `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
linkedin: (url) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`,
};
function handleFormEvent(event: Core.FormEvent) {
if (event.name === 'shareEvent') {
const network = event.detail as string;
const buildUrl = SHARE_URLS[network];
if (buildUrl) {
window.open(buildUrl(window.location.href), '_blank', 'noopener,noreferrer');
}
}
}
<React.FormComponent
formDef={formDef}
formConfig={formConfig}
formEvent={handleFormEvent}
// ...other props
/>