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 ParameterDescription
RuleName extends stringThe existing rule names

Parameters

ParameterTypeDescription
params{ engine: Engine<RuleName>; pageBuilder: PageBuilder<RuleName>; }-
params.engineEngine<RuleName>The Publicodes engine instance used to compute form fields
params.pageBuilder?PageBuilder<RuleName>Function to split fields into pages
targetsRuleName[]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:

  1. Computing the next fields based on the engine and targets
  2. Splitting these fields into pages using the provided pageBuilder
  3. Moving to the first page of questions

Example

const engine = new Engine(rules)
const formState = initFormState({ engine }, 'rule1', 'rule2')