GhostForm
GhostForm and its composable, useGhostForm, add schema-backed submission to a native form. Field errors stay hidden until the first submit by default, out-of-order async results are discarded, and native form reset is coordinated. Validation runs through any Standard Schema v1 validator. Import both from @ghostvue/vue.
Schema validation and transformation
Typed Standard Schema v1 form with input transformation, nested paths, form-level alert, and standalone field opt-out.
You keep ownership of the reactive form values, bound to inputs, selects, radio groups, and other controls with v-model. When validation passes, the submit event receives the schema's transformed output without mutating your values. A GhostField with a name reads its errors from the form: it marks its control invalid, shows the message in its error part, and links the message to the control. A field without a name stays driven by its own props.
Async checks and server errors
Pending submit state via waitUntil, out-of-order validation safety, and imperative setFieldErrors.
Validation can be async. The form reports that it is validating only while the latest check runs: results that resolve out of order, or after a reset, are discarded. In a submit handler, pass an async save to waitUntil(promise). The form then stays submitting, busy, and protected from duplicate submits until the save settles.
Map server validation errors back to fields with setFieldErrors, or to a GhostInlineAlert with setFormErrors. Both helpers come with the submit event and are also on the template ref.
Nested paths and composite controls
Dynamic nested array paths with blur validation and GhostField scoped error display.
Dot paths such as billing.postalCode and endpoints.0.url map nested object and array issues straight to the field with that name. Composite popups such as GhostSelect keep Enter inside the open listbox and defer blur validation until focus leaves both the field and its controlled popup.
A date picker in a named field adds its own errors to that field, such as a rejected range or an uncommitted draft. They block submit and appear in fieldErrors and issues, but the picker owns them, so clearErrors and setFieldErrors leave them in place.
Standard Schema v1 compatibility
GhostForm accepts any Standard Schema v1 validator, such as Zod, Valibot, ArkType, Yup, or an inline ~standard object, with no extra runtime dependencies:
import { z } from 'zod'
import { GhostForm, type GhostFormSubmitPayload } from '@ghostvue/vue'
const schema = z.object({
seats: z.coerce.number().int().min(1),
})- Missing, empty (
[]), or symbol-containing issue paths map toformErrors. - String and numeric path segments join with
.intofieldErrors. - By default (
validateOn="submit",revalidateOn="change"), fresh forms avoid premature errors until the first submit, then revalidate on edit as the user repairs values.
SSR and initialIssues
Neither the component nor the composable validates during setup or SSR. Pass initialIssues from a server action or loader to render seeded field and form errors on the server, with deterministic hydration and matching aria-describedby links.
Accessibility
- Renders a native
<form>element (novalidateby default so Standard Schema v1 owns validation messages while inputtypeandrequiredhints remain). - On failed submit (
focusInvalidOnSubmit="true"), moves focus after DOM flush to the first enabled focusable[aria-invalid="true"]control (or the first enabled radio inside an invalidGhostRadioGroup), unless focus already sits inside an active external modal trap. - Sets
aria-busy="true"during active submission while leaving backgroundblur/changechecks quiet. - Leaves form controls enabled during pending submits so keyboard focus is never dropped to
<body>.
Advanced: headless composable
For custom form hosts without <GhostForm>, call useGhostForm and spread form.formProps.value onto a native <form> element:
Lower-level useGhostForm binding formProps onto a native form element.
API
See the generated component reference for the complete machine-readable contract and the approved GhostForm specification for full state and race invariants.
| Prop | Type | Default | Description |
|---|---|---|---|
focusInvalidOnSubmit | boolean | true | Moves focus after DOM flush to the first focusable invalid control when submit fails. |
initialIssues | readonly StandardSchemaV1.Issue[] | — | Optional seed issues partitioned synchronously at setup without calling validate(). |
novalidate | boolean | true | Sets HTML novalidate on <form> so Standard Schema v1 owns submit validation. |
revalidateOn | GhostFormValidateTrigger | "change" | Trigger that re-validates a field once it has visible issues or after submit. |
schema | TSchema | Required | Standard Schema v1 validator (schema['~standard'].version === 1). |
schemaOptions | StandardSchemaV1.Options | — | Optional vendor options forwarded as the second argument to validate(). |
validateOn | GhostFormValidateTrigger | "submit" | Trigger that first reveals issues on an untouched field before the first submit. |
values | NoInfer<TValues> | Required | Consumer-owned input state passed to schema['~standard'].validate. |
| Event | Payload | Description |
|---|---|---|
invalid | GhostFormInvalidPayload<TValues> | Emitted when a submit attempt fails schema validation on an active epoch. |
reset | Event | null | Emitted after imperative reset() or a non-cancelled native form reset completes. |
submit | GhostFormSubmitPayload<StandardSchemaV1.InferOutput<TSchema>, TValues> | Emitted with transformed schema output and waitUntil/setFieldErrors helpers when submit validation succeeds. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Form controls, GhostField instances, and action buttons receiving GhostFormSlotProps. |
Slot props and template ref
The default slot and the useGhostForm return carry the form state and actions. The template ref exposes the actions and the native form element.
| Member | In the slot | On the ref | Description |
|---|---|---|---|
fieldErrors, formErrors, issues | Yes | No | Current errors by field path, form-level errors, and the raw schema issues. |
isValidating | Yes | No | true while the latest validation runs. |
isSubmitting | Yes | No | true from submit until any waitUntil promise settles. |
isPending | Yes | No | true while validating or submitting. |
fieldProps(path) | Yes | No | The name and invalid bindings for a field path. |
validate(), validateField(path) | Yes | Yes | Run the schema for the whole form or one field. |
submit(event?) | Yes | Yes | Validate and emit submit or invalid, as a native submit does. |
setFieldErrors(path, messages), setFormErrors(messages) | Yes | Yes | Show server errors on a field or on the form. |
clearErrors(path?), reset() | Yes | Yes | Clear errors, or reset errors, tracking state, and pending validation. |
element | No | Yes | The native <form>, or null before mount. |