Skip to content
Open Cloud

Custom Actions & Progress ​

Replace the built-in form buttons and step progress bar with your own components. Useful when your project has a design system and the default unstyled HTML doesn't fit. Both are keys of the layout prop. For fields and the other layout slots, see Custom Fields.

Custom actions component ​

Pass your component as layout.actions:

vue
<script setup lang="ts">
import { FormRenderer } from '@formhaus/vue'
import MyFormActions from './MyFormActions.vue'
</script>

<template>
  <FormRenderer
    :definition="definition"
    :layout="{ actions: MyFormActions }"
    @submit="onSubmit"
  />
</template>
tsx
import { FormRenderer } from '@formhaus/react'
import { MyFormActions } from './MyFormActions'

<FormRenderer
  definition={definition}
  layout={{ actions: MyFormActions }}
  onSubmit={handleSubmit}
/>

The actionsComponent prop still works until 2.0 and warns once in development. Its component gets the props below without rootProps. FormhausForm takes its own actionsComponent without the warning.

Your component receives pre-computed convenience props so you don't need to re-derive button labels or visibility:

PropTypeDescription
primaryLabelstring?Resolved label for the primary button: the continue label, the submit label or the submit label
showPrimaryboolean?False when the current step hides Next with next: false; final Submit remains visible
primaryDisabledboolean?True while the disabled conditions of the primary action match. Only a layout.actions gets it. Disable the button while primaryDisabled or loading is set
showBackboolean?Whether the back button should be shown
backLabelstring?Resolved label for the back button
showSkipboolean?Whether the skip button should be shown
skipLabelstring?Label for the skip button, defaults to the skip label or "Skip"
loadingboolean?Parent loading state or pending navigation/submission, including hooks
cancelActionFormAction?Cancel button config
testIds{ submit?, next?, back? }Test ids of the buttons, when the renderer has testIds
rootProps{ 'data-fh': 'actions' }Spread on the root element, so focus after an error never lands on a button. See Root props

In React, call onPrimary for the primary action, onBack for back and onSkip for skip. In Vue, emit primary, back and skip.

Vue example ​

vue
<script setup lang="ts">
import { formActionsEmits, formActionsProps } from '@formhaus/vue'

defineProps(formActionsProps)
const emit = defineEmits(formActionsEmits)
</script>

<template>
  <div v-bind="rootProps" class="my-actions">
    <button v-if="showBack" type="button" :disabled="loading" @click="emit('back')">{{ backLabel }}</button>
    <button v-if="showPrimary !== false" type="button" @click="emit('primary')" :disabled="loading">{{ primaryLabel }}</button>
  </div>
</template>

React example ​

tsx
import type { FormActionsProps } from '@formhaus/react'

export function MyFormActions({
  primaryLabel, showPrimary = true, showBack, backLabel, loading,
  onPrimary, onBack, rootProps,
}: FormActionsProps) {
  return (
    <div {...rootProps} className="my-actions">
      {showBack && <button type="button" disabled={loading} onClick={onBack}>{backLabel}</button>}
      {showPrimary && <button type="button" disabled={loading} onClick={onPrimary}>{primaryLabel}</button>}
    </div>
  )
}

Raw props ​

PropTypeDescription
submitActionFormAction?Label and variant for the submit button
nextActionFormAction | false?Next button config of the current step
backActionFormAction | false?Back button config, or false to hide
cancelActionFormAction?Cancel button config
skipActionFormAction?Skip button config of the current step
isFirstStepbooleanWhether this is the first step
isLastStepbooleanWhether this is the last step
isMultiStepbooleanWhether the form has multiple steps
loadingboolean?Parent loading state or pending navigation/submission, including hooks

In Vue, you can also emit submit, next, back, cancel events directly. In React, call onSubmit, onNext, onBack, onCancel callbacks.

Custom progress component ​

Pass your component as layout.progress:

vue
<template>
  <FormRenderer
    :definition="definition"
    :layout="{ progress: MyStepProgress }"
    @submit="onSubmit"
  />
</template>
tsx
<FormRenderer
  definition={definition}
  layout={{ progress: MyStepProgress }}
  onSubmit={handleSubmit}
/>

The progressComponent prop still works until 2.0 and warns once in development. Its component gets no rootProps and no marks, and gets steps only when the renderer has stepErrorMarks.

Your component receives these props:

PropTypeDescription
currentnumberCurrent step number (1-based)
totalnumberTotal visible steps
stepTitlestring?Title of the current step
stepDescriptionstring?Description of the current step
headingLevel1 to 6, optionalHeading level for the step title, from the renderer's headingLevel prop. The built-in progress renders <h2> by default
stepsFormStepStatus[]?Steps of the active path as { id, title, errorCount, errorsLabel }. errorsLabel is the stepErrors label when the step has errors. A layout.progress always gets them, a progressComponent only with stepErrorMarks
marksboolean?true when the renderer has stepErrorMarks, else false. Only a layout.progress gets it
counterLabelstring?Step counter text from the stepOf label, such as Step 2 of 3
stepErrorCountnumber?Number of field errors on the current step
stepErrorsLabelstring?The stepErrors label for the current step, such as Errors: 2, when it has errors. Only a layout.progress gets it
rootProps{ 'data-fh': 'progress' }Spread on the root element, so focus after an error never lands on a step button

The progress component only renders for multi-step forms. The built-in FormStepProgress draws the step list only when marks is true. Rendered on its own, it draws steps unless marks is false.

Combining both ​

Field types go to components, everything around them to layout:

vue
<template>
  <FormRenderer
    :definition="definition"
    :components="{ phone: CustomPhoneInput }"
    :layout="{ actions: MyFormActions, progress: MyStepProgress }"
    @submit="onSubmit"
  />
</template>
tsx
<FormRenderer
  definition={definition}
  components={{ phone: CustomPhoneInput }}
  layout={{ actions: MyFormActions, progress: MyStepProgress }}
  onSubmit={handleSubmit}
/>

A key you leave out keeps the built-in component.

Headless renderer ​

FormRenderer imports the built-in native fields, actions and step progress. They stay in your bundle even when you replace all of them. See Choose a renderer for the three paths and Bundle size for their sizes. If you map every field type you use and pass your own actions and progress components, use HeadlessFormRenderer. It takes the same props and events as FormRenderer, but it does not import any built-in component. This drops the built-in fields from your bundle.

vue
<script setup lang="ts">
import { HeadlessFormRenderer } from '@formhaus/vue'
</script>

<template>
  <HeadlessFormRenderer
    :definition="definition"
    :components="{ text: MyInput, email: MyInput, select: MySelect }"
    :layout="{ actions: MyFormActions, progress: MyStepProgress }"
    @submit="onSubmit"
  />
</template>
tsx
import { HeadlessFormRenderer } from '@formhaus/react'

<HeadlessFormRenderer
  definition={definition}
  components={{ text: MyInput, email: MyInput, select: MySelect }}
  layout={{ actions: MyFormActions, progress: MyStepProgress }}
  onSubmit={handleSubmit}
/>

HeadlessFormRenderer supports the same lifecycle hooks and awaited submission. Custom fields must implement explicit activation for autoAdvance; custom actions must honor showPrimary and loading as above.

HeadlessFormRenderer has no fallbacks:

  • A field type with no mapped component renders an "Unsupported field type" placeholder. In development the renderer also warns with missing-component.
  • Without layout.actions, the form renders no buttons.
  • Without layout.progress, a multi-step form renders no progress bar.
  • The other layout slots keep the built-in markup when left out.

Render one field ​

FormhausField renders a single field with the built-in components as fallbacks. Pass components to override some types. Both packages also export every built-in field (TextField, TextareaField, SelectField, AutocompleteField, MultiselectField, CheckboxField, RadioField, SwitchField, FileField, DateField, DateTimeField, TimeField, ScaleField, HiddenField) and defaultFieldComponents.

vue
<FormhausField :field="field" v-model="value" />
tsx
<FormhausField field={field} value={value} onChange={setValue} onBlur={() => {}} />

Exported types ​

Import the prop interfaces to type your custom components:

ts
// Vue
import type { FormActionsProps, FormStepProgressProps, LayoutComponentMap, RootProps } from '@formhaus/vue'

// React
import type { FormActionsProps, FormStepProgressProps, LayoutComponentMap, RootProps } from '@formhaus/react'

Runtime props in Vue ​

The Vue SFC compiler turns defineProps<T>() into runtime prop declarations, and for that it must resolve T. It often cannot resolve a type imported from a package, and fails or declares a prop with the wrong runtime type. @formhaus/vue exports runtime declarations for every custom component. Pass them to defineProps and defineEmits; the props stay fully typed.

vue
<script setup lang="ts">
import { groupItemComponentProps } from '@formhaus/vue'

const props = defineProps(groupItemComponentProps)
</script>
ComponentPropsEmits
FieldfieldComponentPropsfieldComponentEmits
ActionsformActionsPropsformActionsEmits
Step progressformStepProgressProps
Fields containerfieldsContainerProps
SectionsectionComponentProps
GroupgroupComponentProps
Group itemgroupItemComponentProps
Remove dialogconfirmDialogComponentProps
Error summaryerrorSummaryComponentProps
Form errorsformErrorsComponentProps
A wrapper around FormRendererformRendererProps

Each declares every prop of the matching interface, such as FieldComponentProps for fieldComponentProps. Props you do not use are harmless. formStepProgressProps defaults headingLevel to 2 and marks to true.

Form events ​

Track the form lifecycle via onFormEvent (React) or @formEvent (Vue). Event type names are snake_case, the usual convention for analytics tools:

tsx
<FormRenderer
  definition={definition}
  onFormEvent={(event) => analytics.track(event.type, event)}
  onSubmit={handleSubmit}
/>
vue
<FormRenderer
  :definition="definition"
  @form-event="(event) => analytics.track(event.type, event)"
  @submit="onSubmit"
/>

Events emitted:

EventWhenPayload
form_viewedThe form is shown. Once per engine: a remount or a new definition reports it again
step_viewedA step becomes active: on first show and after every step changestepId, stepIndex
step_completedUser advances past a step. The last step reports form_submitted insteadstepId
step_skippedUser skips a stepstepId
step_redirectedgoToStep() cannot open the requested step and opens another onerequestedStepId, stepId, reason: 'unknown-step', 'not-on-path' or 'blocked'
field_focusedUser focuses a fieldfieldKey
field_blurredUser leaves a fieldfieldKey, hasValue
field_shownA field's show condition, or its section's, starts to pass. Reports fields on every step, not only the current one, and can fire on reset()fieldKey
field_hiddenA field's show condition, or its section's, stops passing. Reports fields on every step, not only the current one, and can fire on reset()fieldKey
field_errorStep validation, form validation or the submit handler fails with field errorsfieldKey, error
form_submittedValidation and onBeforeSubmit pass, right before the submit handler runsfieldCount
form_submit_succeededThe submit handler resolves without { ok: false }
form_submit_failedSubmit fails validation, or the submit handler returns { ok: false } or throwsreason: 'validation', 'rejected' or 'error'. status for 'error' when the thrown error has a numeric status, such as CloudError
form_resetengine.reset() runs after the form is shown

The order of events is in the specification. Events carry step ids and field keys, never step titles or labels with recalled answers. Group item fields report their path as fieldKey, such as people.0.name. field_shown and field_hidden do not fire for step changes, for added or removed group items, or for fields without a condition. A reset during a pending submit is still followed by that submit's form_submit_succeeded or form_submit_failed. An error thrown by the handler does not stop the form. It is rethrown in a microtask. All events are optional. If you don't pass a handler, nothing fires. The event type is FormEvent.

FormEngine reports the same events, except field_focused and field_blurred, through the onFormEvent option. See form events.

Next steps ​