Skip to content

Inline when

Sometimes you need a condition that’s only used once. Naming it as a state would be overkill. Use { when: '<expression>' } to express it inline directly on the widget.

Inline when accepts the same reactive expression syntax as named states — $form.<path>, comparisons, logical operators.

A “Number of pets” input that only renders when the user opted into pet-friendly hotels.

No formConfig.states entry is needed — the expression sits on the widget.

import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
const formDef = [
gui.inputs.booleanInput('includePets', { label: 'I am traveling with pets' }),
gui.inputs.numberInput('pets', {
label: 'Number of pets',
include: { when: '$form.includePets === true' },
}),
];
export function MyForm() {
return <GuiForm config={{ formDef }} />;
}

No "states" block is needed — the expression sits on the widget.

{
"form": [
{
"kind": "input",
"type": "checkbox",
"path": "includePets",
"label": "I am traveling with pets"
},
{
"kind": "input",
"type": "number",
"path": "pets",
"label": "Number of pets",
"include": { "when": "$form.includePets === true" }
}
]
}

Wire the parsed JSON into your form component the same way as any other JSON formDef:

import { GuiForm } from '@golemui/gui-react';
import formDef from './my-form.json';
export function MyForm() {
return <GuiForm config={{ formDef }} />;
}
  • Use inline when when the condition appears once and reads naturally at the call site.
  • Use a named state when the same condition gates multiple widgets, drives prop overrides, or is referenced from event handlers.