buildFormPage
API / @publicodes/forms / buildFormPage
function buildFormPage<Name>(
page,
engine,
targets,
lastAnswered): FormPageElementProp & EvaluatedFormElement[]
Defined in: buildFormPage.ts:59
Builds an interactive form page with dynamic field behavior based on user progression.
This function enhances form elements with UI-specific behaviors needed for a step-by-step form experience:
- Progressive disclosure: Fields are shown/hidden based on their relevance to target computations
- Focus management: Auto-focuses the first unanswered field when entering a new page
- Field dependencies: Disables fields that are no longer relevant for target calculations
- Visual cleanup: Automatically collapses irrelevant fields that appear after the last answered question
Use this when building multi-step forms where you want to guide users through a sequence of questions while maintaining a clean interface by hiding unnecessary fields.
Type Parameters
Type Parameter |
---|
Name extends string |
Parameters
Parameter | Type | Description |
---|---|---|
page | Name [] | Array of rule names representing form fields to display |
engine | Engine <Name > | Publicodes engine instance containing rules and current situation |
targets | Name [] | Target rules that determine which fields are useful |
lastAnswered | null | Name | The most recently answered field, used for progressive disclosure |
Returns
FormPageElementProp
& EvaluatedFormElement
[]
Array of form elements enhanced with UI interaction states (hidden, disabled, autofocus)
Example
// In a form wizard component
const pageElements = buildFormPage(
['person . age', 'person . income'],
engine,
['taxes . eligible'],
'person . age'
)
// Returns elements with proper focus/visibility for a form wizard interface