Skip to content

Vue Form API

Reference every Form Vue component, prop, slot, event, function, and public type.

Back to the Vue forms guide

API

Vue package: @sectile/vue/form

Components
  • FormRoot
  • FormSelector
  • FormFieldSelector
  • FormField
  • FormLabel
  • FormDescription
  • FormMessage
  • FormSummary
  • FormReset
  • FormSubmit
Advanced control presets
  • compositeControlCapabilities
  • hiddenInputSubmissionCapabilities
  • hiddenSelectSubmissionCapabilities
  • hiddenValueSubmissionCapabilities
  • nativeInputControlCapabilities

Functions

defineFormSubmission

ts
function defineFormSubmission<const Schema extends FormSchema<object, object>>(definition: FormSchemaSubmissionDefinition<Schema>): FormSchemaSubmissionDefinition<Schema>

useFormSelector

ts
function useFormSelector<Selected>(selector: FormSelectorFunction<Selected>, options: FormSubscribeOptions<Selected> = {}): Readonly<ShallowRef<Selected>>

useFormFieldSelector

ts
function useFormFieldSelector<Selected>(id: string, selector: FormFieldSelectorFunction<Selected>, options: FormSubscribeOptions<Selected> = {}): Readonly<ShallowRef<Selected>>

useFormFieldController

ts
function useFormFieldController(id: string): FormFieldController

provideFormControlOwner

ts
function provideFormControlOwner(): void

useCompositeFormControl

ts
function useCompositeFormControl(options: {
  readonly root: FormElementSource;
  readonly focusTarget?: FormElementSource;
  readonly validationTarget?: FormElementSource;
  readonly submissions?: FormSubmissionSource;
  readonly labelMode?: FormLabelMode;
  readonly reset?: () => void;
  readonly getValue?: () => unknown;
  readonly isValueEqual?: (current: unknown, baseline: unknown) => boolean;
}): FormControlParticipation

useFormControl

ts
function useFormControl(registration: FormControlRegistration): FormControlParticipation

useNativeInputFormControl

ts
function useNativeInputFormControl(element: Readonly<ShallowRef<HTMLInputElement | HTMLTextAreaElement | null | undefined>>, options: {
    readonly reset?: () => void;
    readonly getValue?: () => unknown;
    readonly isValueEqual?: (current: unknown, baseline: unknown) => boolean;
  } = {}): FormControlParticipation

Props

FormRootProps

issues

Validation issues supplied by the application.

mapSubmitError

Maps a thrown or rejected submission error to a safe application-facing failure.

onSubmit

Handles a validated native submission and may report success, a submission failure, or server issues.

revalidateOn

Interaction events that rerun the active validation intent after validation fails.

schema

Standard Schema used for authoritative submission validation and output transformation.

validate

Validates the current field and returns application issues.

validateOn

Interaction events that run validation before the first submission attempt.

FormFieldProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

disabled

Whether interaction is unavailable.

form

ID of the native form associated with the control.

id

Stable ID used to connect related parts.

name

Name used for native form submission.

readonly

Whether the value can be inspected but not changed.

required

Whether the control must contain a valid value before submission.

FormSelectorProps

equals

Returns whether two selected snapshots are equivalent.

select

Selects the form or field state exposed to the slot.

FormFieldSelectorProps

equals

Returns whether two selected snapshots are equivalent.

id

Stable ID used to connect related parts.

select

Selects the form or field state exposed to the slot.

FormPartProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

Slots

FormRootSlotProps

dirty

Whether the current value differs from its baseline.

reinitialize

Adopts the current values as the new dirty baseline and resets form metadata unless preserved.

replaceIssues

Replaces validation issues for one source.

reset

Runs the native form reset and clears Form state; controlled values remain application-owned.

state

Complete current form state.

submission

Current submission lifecycle snapshot.

submitCount

Number of submission attempts derived from submission.count.

submitFailed

Marks the identified submission as failed.

submitStarted

Starts submission and returns its generation token.

submitSucceeded

Marks the identified submission as successful.

submitted

Whether submission has been attempted.

touched

Whether the user has interacted with the field.

valid

Whether current validation has no issues.

validation

Current validation lifecycle snapshot.

FormFieldSlotProps

clearIssues

Clears validation issues for this field.

controlId

ID assigned to the semantic control.

describedBy

Space-separated IDs that describe the control.

descriptionId

ID assigned to field help text.

dirty

Whether the current value differs from its baseline.

id

Stable ID for this field or item.

issues

Current canonical validation issues.

labelId

ID assigned to the field label.

messageId

ID assigned to the field error message.

relatedIssues

Issues owned elsewhere that also make this field invalid.

removeIssue

Removes one field issue by ID.

replaceIssues

Replaces validation issues for one source.

setMeta

Updates mutable metadata for this field.

touched

Whether the user has interacted with the field.

upsertIssue

Adds or replaces one field issue.

valid

Whether current validation has no issues.

FormSummarySlotProps

firstIssue

First canonical issue, or null.

issues

Current canonical validation issues.

serverIssues

Current canonical server issues.

submission

Current submission lifecycle snapshot.

valid

Whether current validation has no issues.

validation

Current validation lifecycle snapshot.

FormSubmitSlotProps

canSubmit

Whether the form is valid and not currently submitting.

submission

Current submission lifecycle snapshot.

submitting

Whether form submission is currently in progress.

valid

Whether current validation has no issues.

Events

FormSubmitEvent

NameTypeRequired
formDataFormDataYes
valuesReadonly<Values>Yes
submitterHTMLElement | nullYes
stateFormStateYes
reinitialize(options?: FormReinitializeOptions) => voidYes
nativeEventSubmitEventYes
defaultPreventedbooleanYes
preventDefault() => voidYes
stopPropagation() => voidYes
stopImmediatePropagation() => voidYes

Other types

FormState

NameTypeRequired
validationFormValidationStateYes
submissionFormSubmissionStateYes
touchedbooleanYes
dirtybooleanYes
validbooleanYes
fieldsreadonly FormFieldState<string>[]Yes
issuesreadonly FormIssue<string>[]Yes
allIssuesreadonly FormIssue<string>[]Yes

FormFieldState

NameTypeRequired
idstringYes
namestring | nullYes
touchedbooleanYes
dirtybooleanYes
validbooleanYes
issuesreadonly FormIssue<string>[]Yes
relatedIssuesreadonly FormIssue<string>[]Yes

FormFieldMetaInput

NameTypeRequired
namestring | null | undefined
touchedboolean | undefined
dirtyboolean | undefined

FormSubscribeOptions

NameTypeRequired
equals((previous: Selected, next: Selected) => boolean) | undefined

FormSelectorFunction

ts
type FormSelectorFunction<Selected> = (state: FormState) => Selected

FormFieldSelectorFunction

ts
type FormFieldSelectorFunction<Selected> = (field: FormFieldState | null) => Selected

FormIssue

NameTypeRequired
idStableIDYes
messagestringYes
sourceFormIssueSourceYes
fieldIdstring | undefined
relatedFieldIdsreadonly string[] | undefined

FormIssueSource

ts
type FormIssueSource = 'native' | 'field' | 'form' | 'validate' | 'schema' | 'server'

FormReinitializeOptions

NameTypeRequired
preserve{ readonly touched?: boolean; readonly validation?: boolean; readonly submission?: boolean; } | undefined

FormValues

ts
type FormValues<Shape extends object = Record<string, unknown>> = Readonly<Shape>

FormSchema

ts
type FormSchema<Input extends object = Record<string, unknown>, Output extends object = Input> = StandardSchemaV1<FormValues<Input>, FormValues<Output>>

FormSchemaInput

ts
type FormSchemaInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>

FormSchemaOutput

ts
type FormSchemaOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>

FormIssueInput

NameTypeRequired
idstring | undefined
messagestringYes
pathFormFieldPath | undefined
relatedPathsreadonly FormFieldPath[] | undefined

FormSubmitIssue

ts
type FormSubmitIssue = FormIssueInput

FormSubmitResult

ts
type FormSubmitResult =
| void
  | { readonly ok: true }
  | {
      readonly ok: false;
      readonly failure?: FormSubmissionFailure;
      readonly issues?: readonly FormSubmitIssue[];
    }

FormSubmitHandler

ts
type FormSubmitHandler<Values extends object = Record<string, unknown>> = (event: FormSubmitEvent<Values>) => FormSubmitResult | PromiseLike<FormSubmitResult>

FormSubmissionDefinition

NameTypeRequired
schemaundefined
onSubmitFormSubmitHandler<Record<string, unknown>>Yes

FormSchemaSubmissionDefinition

NameTypeRequired
schemaSchemaYes
onSubmitFormSubmitHandler<FormSchemaOutput<Schema>>Yes

FormSubmitErrorMapper

ts
type FormSubmitErrorMapper =
(
  reason: unknown,
) => FormSubmissionFailure | undefined

FormResetHandler

ts
type FormResetHandler = () => void

FormStateChangeHandler

ts
type FormStateChangeHandler = (state: FormState) => void

FormInteractionValidationTrigger

ts
type FormInteractionValidationTrigger = Exclude<FormValidationTrigger, 'submit'>

FormValidateContext

NameTypeRequired
triggerFormValidationTriggerYes
intentFormValidationIntentYes
changedFieldIdstring | nullYes
signalAbortSignalYes

FormValidationIssue

NameTypeRequired
messagestringYes
pathFormFieldPath | undefined
relatedPathsreadonly FormFieldPath[] | undefined

FormValidationResult

NameTypeRequired
issuesreadonly FormValidationIssue[] | undefined

FormValidateHandler

ts
type FormValidateHandler<Values extends object = Record<string, unknown>> =
(
  values: FormValues<Values>,
  context: FormValidateContext,
) => FormValidationResult | PromiseLike<FormValidationResult>

FormSubmitStartedAction

ts
type FormSubmitStartedAction = () => number | null

FormSubmitSucceededAction

ts
type FormSubmitSucceededAction = (generation: number) => boolean

FormSubmitFailedAction

ts
type FormSubmitFailedAction =
(
  generation: number,
  result: {
    readonly failure?: FormSubmissionFailure;
    readonly issues?: readonly FormIssue[];
  },
) => boolean

FormReplaceIssuesAction

ts
type FormReplaceIssuesAction =
(
  source: FormIssueSource,
  issues: readonly FormIssue[],
) => boolean

FormResetAction

ts
type FormResetAction = () => void

FormReinitializeAction

ts
type FormReinitializeAction = (options?: FormReinitializeOptions) => void

FormRootComponent

ts
interface FormRootComponent {
  new <Input extends object = Record<string, unknown>, Output extends object = Input>(props: FormRootPublicProps<Input, Output>): {
    $props: FormRootPublicProps<Input, Output>;
    $slots: {
      default?: (props: FormRootSlotProps) => VNodeChild;
    };
    submitStarted: FormSubmitStartedAction;
    submitSucceeded: FormSubmitSucceededAction;
    submitFailed: FormSubmitFailedAction;
    replaceIssues: FormReplaceIssuesAction;
    reinitialize: FormReinitializeAction;
    reset: FormResetAction;
  };
}

FormFieldController

NameTypeRequired
stateReadonly<ShallowRef<FormFieldState | null>>Yes
setMeta(meta: FormFieldMetaInput) => booleanYes
replaceIssues(source: FormIssueSource, issues: readonly FormIssue[]) => booleanYes
upsertIssue(issue: FormIssue) => booleanYes
removeIssue(issueId: string | number) => booleanYes
clearIssues(source?: FormIssueSource) => booleanYes

FormSelectorComponent

ts
interface FormSelectorComponent {
  new <Selected>(props: FormSelectorProps<Selected>): {
    $props: FormSelectorProps<Selected>;
    $slots: { default?: (props: { readonly selected: Selected }) => VNodeChild };
  };
}

FormFieldSelectorComponent

ts
interface FormFieldSelectorComponent {
  new <Selected>(props: FormFieldSelectorProps<Selected>): {
    $props: FormFieldSelectorProps<Selected>;
    $slots: { default?: (props: { readonly selected: Selected }) => VNodeChild };
  };
}

FormControlCapabilities

NameTypeRequired
idboolean | undefined
describedByboolean | undefined
invalidboolean | undefined
labelledByboolean | undefined
requiredboolean | undefined
disabledboolean | undefined
readonlyboolean | undefined

FormControlParticipation

NameTypeRequired
participatingbooleanYes
controlPropsComputedRef<Readonly<Record<string, unknown>>>Yes

FormControlRegistration

NameTypeRequired
elementFormElementSource<HTMLElement>Yes
semanticControlFormElementSource<HTMLElement> | undefined
focusTargetFormElementSource<HTMLElement> | undefined
validationTargetFormElementSource<HTMLElement> | undefined
submissionsFormSubmissionSource | undefined
labelModeFormLabelMode | undefined
capabilitiesFormControlCapabilities | undefined
explicitreadonly FormMetadataAttribute[] | undefined
reset(() => void) | undefined
getValue(() => unknown) | undefined
isValueEqual((current: unknown, baseline: unknown) => boolean) | undefined

FormElementSource

ts
type FormElementSource<ElementType extends HTMLElement = HTMLElement> =
| Readonly<ShallowRef<ElementType | null | undefined>>
  | (() => ElementType | null)

FormLabelMode

ts
type FormLabelMode = 'for' | 'labelledby' | 'legend'

FormMetadataAttribute

ts
type FormMetadataAttribute =
| 'id'
  | 'name'
  | 'form'
  | 'required'
  | 'disabled'
  | 'readonly'
  | 'aria-describedby'
  | 'aria-errormessage'
  | 'aria-invalid'
  | 'aria-labelledby'
  | 'aria-disabled'
  | 'aria-required'
  | 'aria-readonly'

FormSubmissionCapabilities

NameTypeRequired
nameboolean | undefined
formboolean | undefined
requiredboolean | undefined
disabledboolean | undefined
readonlyboolean | undefined

FormSubmissionRegistration

NameTypeRequired
elementFormElementSource<FormControlSubmissionElement>Yes
relativeNameFormControlRelativePath | undefined
capabilitiesFormSubmissionCapabilities | undefined
explicitreadonly FormMetadataAttribute[] | undefined

FormSubmissionSource

ts
type FormSubmissionSource =
| readonly FormSubmissionRegistration[]
  | (() => readonly FormSubmissionRegistration[])

Released under the MIT License.