Skip to content

GkForm

Renders a native <form> with novalidate, wires submit to async validation, and exposes headless state from createForm via the default slot. Does not register child fields like Vuetify; pair with GkField and app-level validation.

When to use

Use GkForm when you want native form semantics plus async validation state exposed through slot props. Keep field rendering explicit with GkField and control primitives so apps can choose their own validation strategy.

Live Examples

Async validation

Pass validate on GkForm; use isValidating for submit button loading.

Best practice: Handle SubmitEventPromise in submit listeners so you react after validation finishes.

Disabled & readonly

Toggle form-level disabled and readonly; slot exposes isDisabled and isReadonly.

Form flags → disabled: false, readonly: false

API

Props

PropTypeDefaultDescription
controlSize'xs' | 'sm' | 'md' | 'lg' | 'xl'Default visual scale for GkInput, GkSelect, GkTextarea, GkCheckbox, and GkRadio inside this form via GK_FORM_CONTROLS. Omitted: inherits from a parent GkFormControlsProvider or createGkKit({ form: { defaultControlSize } }), else md.
disabledbooleanfalseExposed on slot (future: provide to children)
readonlybooleanfalseExposed on slot
validate() => FormValidationResult | Promise<FormValidationResult>Optional custom validation (e.g. async API). While it runs, slot isValidating is true. Omit for default createForm behavior (errors ref only).

Events

EventPayloadDescription
submitSubmitEventPromiseFired on submit; the event is extended with then / catch / finally bound to the validation Promise (Vuetify-style). Default action is preventDefault. If the listener does not call preventDefault, and validation resolves valid: true, HTMLFormElement.submit() is called (no second submit event).

Default slot (scoped)

PropTypeDescription
errorsFieldValidationResult[]Collected errors (empty until you wire createForm with custom validate)
isDisabledbooleanFrom props
isReadonlybooleanFrom props
isValidatingbooleanWhile validate() runs
isValidboolean | nullLast validation outcome
itemsFormField[]Reserved (currently [])
validate() => Promise<FormValidationResult>Run validation
reset() => voidClears validation state (native reset is handled by the browser reset button)
resetValidation() => voidClears errors only

Headless createForm

Use createForm from god-kit/vue (or vue/form) when you need the same state object without GkForm:

ts
import { createForm } from 'god-kit/vue'

const form = createForm({
  disabled: () => false,
  readonly: () => false,
  async validate() {
    return { valid: true, errors: [] }
  },
})

Examples

Each scenario under Live Examples includes a copyable Vue snippet.

For SubmitEventPromise, handle async results on the event (for example e.then((result) => { … })) so you run code after validation finishes.

Accessibility notes

  • Prefer real submit controls (type="submit") so Enter-to-submit works naturally.
  • Keep labels and error semantics in GkField; GkForm coordinates validation flow, not field accessibility markup.
  • If async validation blocks submission, ensure busy state is visible on submit actions.

Released under the MIT License.