Skip to content

Include & Exclude

Use include to render a widget only when one or more named states are active; use exclude to render it only when they are not active.

Both shapes accept either a list of state names ({ in: [...] }) or a one-off reactive expression ({ when: '...' }).

A boolean toggle reveals a discount-code input only when the user opts in. The state expression reads $form.hasDiscountCode and the discount input declares include: { in: ['hasDiscount'] }.

The state lives in formConfig.states; the include rule sits next to the widget’s other props.

import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
const config = {
formDef: [
gui.inputs.booleanInput('hasDiscountCode', { label: 'I have a discount code' }),
gui.inputs.textInput('discountCode', {
label: 'Discount code',
include: { in: ['hasDiscount'] },
}),
],
formConfig: {
states: { hasDiscount: '$form.hasDiscountCode === true' },
},
};
export function MyForm() {
return <GuiForm config={config} />;
}

When $form.hasDiscountCode flips to true, the discount-code input mounts; flipping it back unmounts the widget and clears its data.

Both include and exclude accept either form. Pick the one that reads best at the call site.

include: { in: ['hasDiscount'] } // active-state list — name defined in formConfig.states
include: { when: '$form.age >= 18' } // ad-hoc expression — no name needed

Use a named state when the same condition appears in multiple places. Use when for one-shot conditions (see Inline when).

exclude is the mirror of include — render the widget unless the state(s) match.

gui.displays.alert('signin-hint', {
text: 'Already have an account? Sign in.',
exclude: { from: ['hasAccount'] },
});