Skip to content

Form Events

Widgets emit named events through the formEvent callback you pass to <gui-form> (or the @form-event emit in Vue). 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.

The event name is just a string you pick — your application listens for it. The form definition declares the wiring inline on the widget, identically in both paths.

import { gui } from '@golemui/gui-shared';
const formDef = [
gui.inputs.dropdown('country', {
onChange: 'countryChanged',
items: ['US', 'CA', 'MX'],
}),
gui.actions.button({ actionType: 'submit', label: 'Submit' }),
];
{
"form": [
{
"kind": "input",
"type": "dropdown",
"path": "country",
"items": ["US", "CA", "MX"],
"on": { "change": "countryChanged" }
},
{
"kind": "action",
"type": "button",
"label": "Submit",
"actionType": "submit"
}
]
}

formEvent is a callback prop in React, an output in Angular, a CustomEvent in Lit, an emitted event (@form-event) in Vue, and a CustomEvent you subscribe to via addEventListener in vanilla JS. Match on event.name and read event.data:

import type { FormEvent, FormSubmitEvent } from '@golemui/core';
import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
const formDef = [
gui.inputs.dropdown('country', { onChange: 'countryChanged', items: ['US', 'CA', 'MX'] }),
gui.actions.button({ actionType: 'submit', label: 'Submit' }),
];
function handleFormEvent(event: FormEvent) {
if (event.name === 'countryChanged') {
console.log('Country selected:', event.data.country);
}
}
function handleFormSubmit(event: FormSubmitEvent) {
console.log('Submitting:', event.data);
}
export function MyForm() {
return (
<GuiForm
config={{ formDef }}
formEvent={handleFormEvent}
formSubmit={handleFormSubmit}
/>
);
}
import type { FormEvent, FormSubmitEvent } from '@golemui/core';
import { GuiForm } from '@golemui/gui-react';
import formDef from './my-form.json';
function handleFormEvent(event: FormEvent) {
if (event.name === 'countryChanged') {
console.log('Country selected:', event.data.country);
}
}
function handleFormSubmit(event: FormSubmitEvent) {
console.log('Submitting:', event.data);
}
export function MyForm() {
return (
<GuiForm
config={{ formDef }}
formEvent={handleFormEvent}
formSubmit={handleFormSubmit}
/>
);
}
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.

In the JSON path, the same events live under the widget’s "on" block: "on": { "click": "...", "change": "...", "load": "...", "filter": "...", "blur": "..." }.

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).