initFormState
API / @publicodes/forms / initFormState
function initFormState<RuleName>(params, ...targets): FormState<RuleName>
Defined in: form.ts:54
Initializes a form state based on the provided engine and targets.
Type Parameters
Type Parameter | Description |
---|---|
RuleName extends string | The existing rule names |
Parameters
Parameter | Type | Description |
---|---|---|
params | { engine : Engine <RuleName >; pageBuilder : PageBuilder <RuleName >; } | - |
params.engine | Engine <RuleName > | The Publicodes engine instance used to compute form fields |
params.pageBuilder ? | PageBuilder <RuleName > | Function to split fields into pages |
…targets | RuleName [] | Array of target rule names to compute fields for |
Returns
FormState
<RuleName
>
A new form state initialized with the first computed page
Remarks
The function creates an initial form state by:
- Computing the next fields based on the engine and targets
- Splitting these fields into pages using the provided pageBuilder
- Moving to the first page of questions
Example
const engine = new Engine(rules)
const formState = initFormState({ engine }, 'rule1', 'rule2')