handleInputChange

API / @publicodes/forms / handleInputChange

function handleInputChange<RuleName>(params): FormState<RuleName>

Defined in: form.ts:233

Updates the form state when a user changes an input value.

Type Parameters

Type ParameterDescription
RuleName extends stringThe existing rule names

Parameters

ParameterTypeDescription
params{ engine: Engine<RuleName>; formState: FormState<RuleName>; id: RuleName; pageBuilder: PageBuilder<RuleName>; value: undefined | string | number | boolean; }-
params.engineEngine<RuleName>The Publicodes engine instance
params.formStateFormState<RuleName>The current state of the form
params.idRuleNameThe rule name identifier of the field being updated
params.pageBuilder?PageBuilder<RuleName>Function to split fields into pages
params.valueundefined | string | number | booleanThe new value for the field

Returns

FormState<RuleName>

A new form state with updated values and potentially new pages

Example

const newState = handleInputChange({
  id: 'usager . age',
  value: 25,
  formState,
  engine
})
// The engine's situation is updated and new pages may be computed