Vue Form API
Reference every Form Vue component, prop, slot, event, function, and public type.
API
Vue package: @sectile/vue/form
FormRootFormSelectorFormFieldSelectorFormFieldFormLabelFormDescriptionFormMessageFormSummaryFormResetFormSubmit
compositeControlCapabilitieshiddenInputSubmissionCapabilitieshiddenSelectSubmissionCapabilitieshiddenValueSubmissionCapabilitiesnativeInputControlCapabilities
Functions
defineFormSubmission
function defineFormSubmission<const Schema extends FormSchema<object, object>>(definition: FormSchemaSubmissionDefinition<Schema>): FormSchemaSubmissionDefinition<Schema>useFormSelector
function useFormSelector<Selected>(selector: FormSelectorFunction<Selected>, options: FormSubscribeOptions<Selected> = {}): Readonly<ShallowRef<Selected>>useFormFieldSelector
function useFormFieldSelector<Selected>(id: string, selector: FormFieldSelectorFunction<Selected>, options: FormSubscribeOptions<Selected> = {}): Readonly<ShallowRef<Selected>>useFormFieldController
function useFormFieldController(id: string): FormFieldControllerprovideFormControlOwner
function provideFormControlOwner(): voiduseCompositeFormControl
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;
}): FormControlParticipationuseFormControl
function useFormControl(registration: FormControlRegistration): FormControlParticipationuseNativeInputFormControl
function useNativeInputFormControl(element: Readonly<ShallowRef<HTMLInputElement | HTMLTextAreaElement | null | undefined>>, options: {
readonly reset?: () => void;
readonly getValue?: () => unknown;
readonly isValueEqual?: (current: unknown, baseline: unknown) => boolean;
} = {}): FormControlParticipationProps
FormRootProps
issuesValidation issues supplied by the application.
mapSubmitErrorMaps a thrown or rejected submission error to a safe application-facing failure.
onSubmitHandles a validated native submission and may report success, a submission failure, or server issues.
revalidateOnInteraction events that rerun the active validation intent after validation fails.
schemaStandard Schema used for authoritative submission validation and output transformation.
validateValidates the current field and returns application issues.
validateOnInteraction events that run validation before the first submission attempt.
FormFieldProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
disabledWhether interaction is unavailable.
formID of the native form associated with the control.
idStable ID used to connect related parts.
nameName used for native form submission.
readonlyWhether the value can be inspected but not changed.
requiredWhether the control must contain a valid value before submission.
FormSelectorProps
equalsReturns whether two selected snapshots are equivalent.
selectSelects the form or field state exposed to the slot.
FormFieldSelectorProps
equalsReturns whether two selected snapshots are equivalent.
idStable ID used to connect related parts.
selectSelects the form or field state exposed to the slot.
FormPartProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
Slots
FormRootSlotProps
dirtyWhether the current value differs from its baseline.
reinitializeAdopts the current values as the new dirty baseline and resets form metadata unless preserved.
replaceIssuesReplaces validation issues for one source.
resetRuns the native form reset and clears Form state; controlled values remain application-owned.
stateComplete current form state.
submissionCurrent submission lifecycle snapshot.
submitCountNumber of submission attempts derived from submission.count.
submitFailedMarks the identified submission as failed.
submitStartedStarts submission and returns its generation token.
submitSucceededMarks the identified submission as successful.
submittedWhether submission has been attempted.
touchedWhether the user has interacted with the field.
validWhether current validation has no issues.
validationCurrent validation lifecycle snapshot.
FormFieldSlotProps
clearIssuesClears validation issues for this field.
controlIdID assigned to the semantic control.
describedBySpace-separated IDs that describe the control.
descriptionIdID assigned to field help text.
dirtyWhether the current value differs from its baseline.
idStable ID for this field or item.
issuesCurrent canonical validation issues.
labelIdID assigned to the field label.
messageIdID assigned to the field error message.
relatedIssuesIssues owned elsewhere that also make this field invalid.
removeIssueRemoves one field issue by ID.
replaceIssuesReplaces validation issues for one source.
setMetaUpdates mutable metadata for this field.
touchedWhether the user has interacted with the field.
upsertIssueAdds or replaces one field issue.
validWhether current validation has no issues.
FormSummarySlotProps
firstIssueFirst canonical issue, or null.
issuesCurrent canonical validation issues.
serverIssuesCurrent canonical server issues.
submissionCurrent submission lifecycle snapshot.
validWhether current validation has no issues.
validationCurrent validation lifecycle snapshot.
FormSubmitSlotProps
canSubmitWhether the form is valid and not currently submitting.
submissionCurrent submission lifecycle snapshot.
submittingWhether form submission is currently in progress.
validWhether current validation has no issues.
Events
FormSubmitEvent
| Name | Type | Required |
|---|---|---|
formData | FormData | Yes |
values | Readonly<Values> | Yes |
submitter | HTMLElement | null | Yes |
state | FormState | Yes |
reinitialize | (options?: FormReinitializeOptions) => void | Yes |
nativeEvent | SubmitEvent | Yes |
defaultPrevented | boolean | Yes |
preventDefault | () => void | Yes |
stopPropagation | () => void | Yes |
stopImmediatePropagation | () => void | Yes |
Other types
FormState
| Name | Type | Required |
|---|---|---|
validation | FormValidationState | Yes |
submission | FormSubmissionState | Yes |
touched | boolean | Yes |
dirty | boolean | Yes |
valid | boolean | Yes |
fields | readonly FormFieldState<string>[] | Yes |
issues | readonly FormIssue<string>[] | Yes |
allIssues | readonly FormIssue<string>[] | Yes |
FormFieldState
| Name | Type | Required |
|---|---|---|
id | string | Yes |
name | string | null | Yes |
touched | boolean | Yes |
dirty | boolean | Yes |
valid | boolean | Yes |
issues | readonly FormIssue<string>[] | Yes |
relatedIssues | readonly FormIssue<string>[] | Yes |
FormFieldMetaInput
| Name | Type | Required |
|---|---|---|
name | string | null | undefined | — |
touched | boolean | undefined | — |
dirty | boolean | undefined | — |
FormSubscribeOptions
| Name | Type | Required |
|---|---|---|
equals | ((previous: Selected, next: Selected) => boolean) | undefined | — |
FormSelectorFunction
type FormSelectorFunction<Selected> = (state: FormState) => SelectedFormFieldSelectorFunction
type FormFieldSelectorFunction<Selected> = (field: FormFieldState | null) => SelectedFormIssue
| Name | Type | Required |
|---|---|---|
id | StableID | Yes |
message | string | Yes |
source | FormIssueSource | Yes |
fieldId | string | undefined | — |
relatedFieldIds | readonly string[] | undefined | — |
FormIssueSource
type FormIssueSource = 'native' | 'field' | 'form' | 'validate' | 'schema' | 'server'FormReinitializeOptions
| Name | Type | Required |
|---|---|---|
preserve | { readonly touched?: boolean; readonly validation?: boolean; readonly submission?: boolean; } | undefined | — |
FormValues
type FormValues<Shape extends object = Record<string, unknown>> = Readonly<Shape>FormSchema
type FormSchema<Input extends object = Record<string, unknown>, Output extends object = Input> = StandardSchemaV1<FormValues<Input>, FormValues<Output>>FormSchemaInput
type FormSchemaInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>FormSchemaOutput
type FormSchemaOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>FormIssueInput
| Name | Type | Required |
|---|---|---|
id | string | undefined | — |
message | string | Yes |
path | FormFieldPath | undefined | — |
relatedPaths | readonly FormFieldPath[] | undefined | — |
FormSubmitIssue
type FormSubmitIssue = FormIssueInputFormSubmitResult
type FormSubmitResult =
| void
| { readonly ok: true }
| {
readonly ok: false;
readonly failure?: FormSubmissionFailure;
readonly issues?: readonly FormSubmitIssue[];
}FormSubmitHandler
type FormSubmitHandler<Values extends object = Record<string, unknown>> = (event: FormSubmitEvent<Values>) => FormSubmitResult | PromiseLike<FormSubmitResult>FormSubmissionDefinition
| Name | Type | Required |
|---|---|---|
schema | undefined | — |
onSubmit | FormSubmitHandler<Record<string, unknown>> | Yes |
FormSchemaSubmissionDefinition
| Name | Type | Required |
|---|---|---|
schema | Schema | Yes |
onSubmit | FormSubmitHandler<FormSchemaOutput<Schema>> | Yes |
FormSubmitErrorMapper
type FormSubmitErrorMapper =
(
reason: unknown,
) => FormSubmissionFailure | undefinedFormResetHandler
type FormResetHandler = () => voidFormStateChangeHandler
type FormStateChangeHandler = (state: FormState) => voidFormInteractionValidationTrigger
type FormInteractionValidationTrigger = Exclude<FormValidationTrigger, 'submit'>FormValidateContext
| Name | Type | Required |
|---|---|---|
trigger | FormValidationTrigger | Yes |
intent | FormValidationIntent | Yes |
changedFieldId | string | null | Yes |
signal | AbortSignal | Yes |
FormValidationIssue
| Name | Type | Required |
|---|---|---|
message | string | Yes |
path | FormFieldPath | undefined | — |
relatedPaths | readonly FormFieldPath[] | undefined | — |
FormValidationResult
| Name | Type | Required |
|---|---|---|
issues | readonly FormValidationIssue[] | undefined | — |
FormValidateHandler
type FormValidateHandler<Values extends object = Record<string, unknown>> =
(
values: FormValues<Values>,
context: FormValidateContext,
) => FormValidationResult | PromiseLike<FormValidationResult>FormSubmitStartedAction
type FormSubmitStartedAction = () => number | nullFormSubmitSucceededAction
type FormSubmitSucceededAction = (generation: number) => booleanFormSubmitFailedAction
type FormSubmitFailedAction =
(
generation: number,
result: {
readonly failure?: FormSubmissionFailure;
readonly issues?: readonly FormIssue[];
},
) => booleanFormReplaceIssuesAction
type FormReplaceIssuesAction =
(
source: FormIssueSource,
issues: readonly FormIssue[],
) => booleanFormResetAction
type FormResetAction = () => voidFormReinitializeAction
type FormReinitializeAction = (options?: FormReinitializeOptions) => voidFormRootComponent
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
| Name | Type | Required |
|---|---|---|
state | Readonly<ShallowRef<FormFieldState | null>> | Yes |
setMeta | (meta: FormFieldMetaInput) => boolean | Yes |
replaceIssues | (source: FormIssueSource, issues: readonly FormIssue[]) => boolean | Yes |
upsertIssue | (issue: FormIssue) => boolean | Yes |
removeIssue | (issueId: string | number) => boolean | Yes |
clearIssues | (source?: FormIssueSource) => boolean | Yes |
FormSelectorComponent
interface FormSelectorComponent {
new <Selected>(props: FormSelectorProps<Selected>): {
$props: FormSelectorProps<Selected>;
$slots: { default?: (props: { readonly selected: Selected }) => VNodeChild };
};
}FormFieldSelectorComponent
interface FormFieldSelectorComponent {
new <Selected>(props: FormFieldSelectorProps<Selected>): {
$props: FormFieldSelectorProps<Selected>;
$slots: { default?: (props: { readonly selected: Selected }) => VNodeChild };
};
}FormControlCapabilities
| Name | Type | Required |
|---|---|---|
id | boolean | undefined | — |
describedBy | boolean | undefined | — |
invalid | boolean | undefined | — |
labelledBy | boolean | undefined | — |
required | boolean | undefined | — |
disabled | boolean | undefined | — |
readonly | boolean | undefined | — |
FormControlParticipation
| Name | Type | Required |
|---|---|---|
participating | boolean | Yes |
controlProps | ComputedRef<Readonly<Record<string, unknown>>> | Yes |
FormControlRegistration
| Name | Type | Required |
|---|---|---|
element | FormElementSource<HTMLElement> | Yes |
semanticControl | FormElementSource<HTMLElement> | undefined | — |
focusTarget | FormElementSource<HTMLElement> | undefined | — |
validationTarget | FormElementSource<HTMLElement> | undefined | — |
submissions | FormSubmissionSource | undefined | — |
labelMode | FormLabelMode | undefined | — |
capabilities | FormControlCapabilities | undefined | — |
explicit | readonly FormMetadataAttribute[] | undefined | — |
reset | (() => void) | undefined | — |
getValue | (() => unknown) | undefined | — |
isValueEqual | ((current: unknown, baseline: unknown) => boolean) | undefined | — |
FormElementSource
type FormElementSource<ElementType extends HTMLElement = HTMLElement> =
| Readonly<ShallowRef<ElementType | null | undefined>>
| (() => ElementType | null)FormLabelMode
type FormLabelMode = 'for' | 'labelledby' | 'legend'FormMetadataAttribute
type FormMetadataAttribute =
| 'id'
| 'name'
| 'form'
| 'required'
| 'disabled'
| 'readonly'
| 'aria-describedby'
| 'aria-errormessage'
| 'aria-invalid'
| 'aria-labelledby'
| 'aria-disabled'
| 'aria-required'
| 'aria-readonly'FormSubmissionCapabilities
| Name | Type | Required |
|---|---|---|
name | boolean | undefined | — |
form | boolean | undefined | — |
required | boolean | undefined | — |
disabled | boolean | undefined | — |
readonly | boolean | undefined | — |
FormSubmissionRegistration
| Name | Type | Required |
|---|---|---|
element | FormElementSource<FormControlSubmissionElement> | Yes |
relativeName | FormControlRelativePath | undefined | — |
capabilities | FormSubmissionCapabilities | undefined | — |
explicit | readonly FormMetadataAttribute[] | undefined | — |
FormSubmissionSource
type FormSubmissionSource =
| readonly FormSubmissionRegistration[]
| (() => readonly FormSubmissionRegistration[])