Skip to content

Form Events

Widgets emit named events through the formEvent callback you pass to <gui-form>. The form definition wires the widget event (a click, a value change, a load) to a name; your application matches on that name and reacts.

In the form definition, attach an event handler to a widget. The handler is a string — the name of the event your application will receive.

import { gui } from '@golemui/gui-shared';
const formDef = [
gui.inputs.dropdown('country', {
onChange: 'countryChanged',
items: ['US', 'CA', 'MX'],
}),
gui.actions.button({ label: 'Submit', onClick: 'submitForm' }),
];

In your application, handle the events:

function handleFormEvent(event) {
switch (event.name) {
case 'countryChanged':
console.log('Country selected:', event.data.country);
break;
case 'submitForm':
console.log('Submitting:', event.data);
break;
}
}
EventEmitted by
onClickAction widgets (button, custom action).
onChangeInput widgets when their value changes.
onLoadDropdowns and lists during initialization.
onFilterDropdowns when the user types a search query.
onBlurInput widgets when focus leaves.

The formEvent callback receives an object with:

  • name — the string you wired in the form definition.
  • data — the current form data at the moment the event fired.
  • detail — optional payload supplied by the widget (e.g. the network id from a custom share button).