Form Generator · Config options

Config options

Passed as the second argument to new FormGenerator(container, config). Answers collected while the form is in use live on formGenerator.answers.

Constructor config

Option Type Description
questions Object[] Question configs from the Steps API (required). Each item needs at least id, step, questionType, fieldName, visible.
totalSteps number Number of steps to render (default: 3).
formType string FormTypes.StepForm ('stepForm') or FormTypes.SectionForm ('sectionForm').
questionRenderers Object Map of questionType → factory, merged over core renderers. Use for module-owned types.
themeColor string CSS custom-property name for stepper / theme accent (e.g. 'color-lta-blue').
isHideProgress boolean When true, hides the stepper.
isBackButtonEnabled boolean Shows the top back control.
showBottomBackButton boolean Shows the bottom back control under the Next / Submit button.
isExitButtonEnabled boolean Shows an exit control. Pair with exitButtonHandler, optional exitButtonLabel / exitButtonClasses.
submitButton Object { title?, dataTarget?, alwaysVisible? } — final-step label, optional data-target, and whether Submit stays visible on section forms.
radioAnswerField string Option property used as the radio answer (default: 'label').
hasSeparator boolean Adds separator styling between question containers.
isSeparator boolean Renders a section separator between steps.
stepVisibility boolean[] Per-step visibility flags (length = totalSteps). Defaults to all true.
conditionalStepsVisiblity boolean When true, empty steps can be skipped in the stepper (typo in source kept for compatibility).
wrapperClasses string[] Optional CSS class per step index, applied to each step wrapper.
backButtonHandlerFirstStep Function Called instead of history.back() when Back is pressed on step 1.
exitButtonHandler Function Called when the exit button is clicked.

Public methods

Methods you typically call from a page after constructing FormGenerator. Callbacks can be registered more than once; each is invoked in registration order.

onChange(callback)

Inherited from FormComponent. Registers a listener for when FormGenerator’s value is set. That happens when the last step submits successfully, or when formValidation() succeeds (it assigns this.value = this.answers).

ParamTypeDescription
callback (value, previousValue) => void value is the answers object (same shape as formGenerator.answers). previousValue is the prior value, if any.

For live updates while the user is still answering, read formGenerator.answers or use onStepChange / question-level handlers. Intermediate answer writes update answers but do not always reassign value.

onStepChange(callback)

Fires after the user moves to another step (Next or Back), once the new step is active. Useful for analytics, lazy-loading, or enabling controls that depend on the current step.

ParamTypeDescription
callback (step) => void step is the 1-based step index after the change (same as formGenerator.currentStep).

onSubmit(callback)

Fires when the user clicks Next on the last step and that step passes stepValidator. The Next button is disabled before handlers run.

ParamTypeDescription
callback (answers, value) => void answers is formGenerator.answers ({ [step]: { [questionId]: answer } }). value is FormGenerator’s value after assign (usually the same answers object).

async formValidation()

Validates every step in order via stepValidator. On full success, sets value to answers (which triggers onChange listeners) and returns true. Stops and returns false at the first failing step.

ReturnsTypeDescription
— Promise<boolean> true if all steps are valid; otherwise false.

async stepValidator(step)

Validates visible, required questions on a single step. Skips optional questions, hidden questions, and any question whose instance defines shouldRender() returning false. Calls each question’s validate(true) and checks that an answer value exists.

Param / returnTypeDescription
step number 1-based step index to validate.
returns Promise<boolean> true if the step is valid; otherwise false.

reRenderForm(updatedStepData)

Re-enables the Next button, jumps to the step of the first updated question, and asks that question instance to re-render with new supporting props (e.g. after an API refresh). Then refreshes Next button enabled state.

ParamTypeDescription
updatedStepData Object[] Array of question-like objects. Uses updatedStepData[0].step and .id to find the question, then passes updatedStepData[0].supportingProps into question.ref.reRenderQuestion(...).

enableSubmitButton()

Re-enables the Next / Submit button when the user is already on the last step (for example after an async check finishes). No-op if the button is missing or the current step is not the last.

ParamTypeDescription
— — No parameters.

getAnswerByQuestionType(questionType, instance?)

Looks up a question by questionType and returns the stored answer value for that question from answers.

Param / returnTypeDescription
questionType string Type string (e.g. 'radio', 'schoolSearch').
instance number Zero-based index when multiple questions share the type (default: 0).
returns * The .value field of the stored answer, or undefined if missing.

unload()

Destroys every question instance (destroy() when available, otherwise remove()), clears refs, and empties the container. Call when leaving the flow or before re-creating FormGenerator in the same element.

ParamTypeDescription
— — No parameters.

Useful properties

Property Type Description
answers Object Live answers keyed by step, then question id: answers[step][questionId].
currentStep number 1-based active step. Setting it updates the stepper / button label (step forms).
questions Object[] Cloned question configs; each rendered question gets a ref to its component instance.
totalSteps number Configured step count.