Skip to content

API Reference

Complete reference for all Vorm types, interfaces, and methods.

useVorm

The main composable that creates a form context.

ts
import { useVorm } from 'vorm-vue';

const vorm = useVorm(schema, options?);

Parameters

ParameterTypeDescription
schemaVormSchemaArray of field definitions
optionsUseVormOptionsOptional configuration

UseVormOptions

ts
interface UseVormOptions {
  i18n?: I18nContext;           // Custom i18n adapter
  initialData?: Record<string, any>;  // Pre-fill form data
}

Return Value

The useVorm composable returns an object with the following properties and methods:

Reactive State

PropertyTypeDescription
formDataRecord<string, any>Reactive form values
errorsComputedRef<Record<string, string | null>>Validation errors per field
touchedRecord<string, boolean>Fields that have been blurred
dirtyRecord<string, boolean>Fields that have been modified
isValidComputedRef<boolean>All validated fields pass
isDirtyComputedRef<boolean>Any field has been modified
isTouchedComputedRef<boolean>Any field has been touched

Validation Methods

MethodSignatureDescription
validateAll() => Promise<boolean>Validate all fields, returns validity
validateFieldByName(name: string) => Promise<void>Validate a single field
clearErrors() => voidClear all validation errors
clearError(name: string) => voidClear error for a specific field

Field Methods

MethodSignatureDescription
updateField(name: string, value: any, options?: { validate?: boolean }) => voidUpdate field value
getFieldOptions(name: string) => Option[]Get resolved options for select fields
bindField(name: string) => ComputedRef<FieldBindings>Get bindings for third-party components

Repeater Methods

MethodSignatureDescription
addRepeaterItem(path: string, item?: any, index?: number) => voidAdd item to repeater
removeRepeaterItem(path: string, index: number) => voidRemove item from repeater
moveRepeaterItem(path: string, from: number, to: number) => voidReorder repeater items
clearRepeater(path: string) => voidRemove all items from repeater

Other

Property/MethodTypeDescription
schemaVormSchemaThe original schema
reset() => voidReset form to initial values

Types

VormSchema

Array of field definitions:

ts
type VormSchema = VormFieldSchema[];

VormFieldSchema

Complete field configuration:

ts
interface VormFieldSchema {
  // Required
  name: string;
  type: FieldType;

  // Text (supports ReactiveString)
  label?: ReactiveString;
  placeholder?: ReactiveString;
  helpText?: ReactiveString;

  // Behavior
  disabled?: ReactiveBoolean;
  required?: boolean;
  showError?: boolean;

  // Validation
  validation?: ValidationRule[];
  validationMode?: ValidationMode;

  // Options (for select, radio, checkbox-group)
  options?: ReactiveOptions;

  // Conditional Rendering
  showIf?: ShowIfCondition;

  // Nested Fields (for repeater)
  fields?: VormFieldSchema[];

  // Styling
  classes?: FieldClasses;
  inheritWrapper?: boolean;
}

FieldType

ts
type FieldType =
  | 'text'
  | 'email'
  | 'password'
  | 'number'
  | 'tel'
  | 'url'
  | 'textarea'
  | 'select'
  | 'checkbox'
  | 'radio'
  | 'date'
  | 'time'
  | 'datetime-local'
  | 'hidden'
  | 'repeater';

ReactiveString

Supports static strings, refs, computed refs, and functions:

ts
type ReactiveString =
  | string
  | Ref<string>
  | ComputedRef<string>
  | (() => string)
  | ((ctx: FormContext) => string);

ReactiveBoolean

Same pattern for boolean values:

ts
type ReactiveBoolean =
  | boolean
  | Ref<boolean>
  | ComputedRef<boolean>
  | (() => boolean)
  | ((ctx: FormContext) => boolean);

FormContext

Context passed to reactive functions:

ts
interface FormContext {
  formData: Record<string, any>;
  readonly errors: Record<string, string | null>;
  readonly isValid: boolean;
  readonly isDirty: boolean;
  readonly isTouched: boolean;
  readonly touched: Record<string, boolean>;
  readonly dirty: Record<string, boolean>;
}

ValidationRule

Define validation rules:

ts
interface ValidationRule {
  rule: BuiltInRuleName | ValidatorFunction;
  message?: ReactiveString;
  params?: any[];
  affects?: string[];
}

type ValidatorFunction = (
  value: any,
  formData: Record<string, any>,
  params?: any[]
) => boolean | string | Promise<boolean | string>;

BuiltInRuleName

Built-in validation rules:

ts
type BuiltInRuleName =
  | 'required'
  | 'email'
  | 'minLength'
  | 'maxLength'
  | 'min'
  | 'max'
  | 'between'
  | 'step'
  | 'pattern'
  | 'matchField';

ValidationMode

When validation triggers:

ts
type ValidationMode = 'onInput' | 'onBlur' | 'onSubmit';

Option

Option format for select/radio fields:

ts
interface Option {
  label: string;
  value: string | number | boolean;
  disabled?: boolean;
}

ReactiveOptions

Supports multiple option sources:

ts
type ReactiveOptions =
  | Option[]
  | Ref<Option[]>
  | ComputedRef<Option[]>
  | (() => Option[])
  | (() => Promise<Option[]>);

ShowIfCondition

Conditional field visibility:

ts
type ShowIfCondition =
  | Record<string, any>                                    // { fieldName: expectedValue }
  | ((formData: Record<string, any>, path: string) => boolean)
  | {
      dependsOn: string;
      condition: (value: any, formData: Record<string, any>) => boolean;
    };

FieldState

State information passed to slots:

ts
interface FieldState {
  error: string | null;
  valid: boolean;
  invalid: boolean;
  validationMode: ValidationMode;
  touched: boolean;
  dirty: boolean;
  initialValue: any;
  classes: string;
}

FieldClasses

Styling classes per element:

ts
interface FieldClasses {
  outer?: string;
  label?: string;
  input?: string;
  help?: string;
  error?: string;
}

FieldBindings

Returned by bindField():

ts
interface FieldBindings {
  modelValue: any;
  'onUpdate:modelValue': (value: any) => void;
  items: Option[];           // Vuetify naming
  options: Option[];         // Generic naming
  error: string | undefined;
  errorMessages: string[];   // Vuetify naming
}

Built-in Validators

Factory Functions

Import and use validator factories:

ts
import {
  required,
  email,
  minLength,
  maxLength,
  min,
  max,
  between,
  step,
  pattern,
  matchField,
} from 'vorm-vue';
ValidatorParametersDescription
required()noneField must have a value
email()noneValid email format
minLength(n)n: numberMinimum string length
maxLength(n)n: numberMaximum string length
min(n)n: numberMinimum numeric value
max(n)n: numberMaximum numeric value
between(min, max)min: number, max: numberValue in range
step(n)n: numberValue must be multiple of step
pattern(regex)regex: RegExpMatch regular expression
matchField(name)name: stringMust match another field

Usage

ts
const schema: VormSchema = [
  {
    name: 'password',
    type: 'password',
    validation: [
      { rule: required() },
      { rule: minLength(8) },
    ],
  },
  {
    name: 'confirmPassword',
    type: 'password',
    validation: [
      { rule: required() },
      { rule: matchField('password') },
    ],
  },
];

i18n Message Keys

Built-in validators return these message keys:

ValidatorKeyParameters
requiredvorm.validation.required
emailvorm.validation.email
minLengthvorm.validation.minLength[min]
maxLengthvorm.validation.maxLength[max]
minvorm.validation.min[min]
maxvorm.validation.max[max]
betweenvorm.validation.between[min, max]
stepvorm.validation.step[step]
patternvorm.validation.pattern
matchFieldvorm.validation.matchField[fieldName]

Components

VormProvider

Provides form context to children:

vue
<VormProvider :vorm="vorm">
  <!-- Children can access vorm context -->
</VormProvider>
PropTypeRequiredDescription
vormReturnType<typeof useVorm>YesForm instance from useVorm

AutoVorm

Auto-generates form UI from schema:

vue
<AutoVorm
  :only="['email', 'password']"
  :exclude-repeaters="false"
  layout="stacked"
  :columns="1"
  as="div"
  @submit="handleSubmit"
  @input="handleInput"
  @blur="handleBlur"
  @validate="handleValidate"
/>
PropTypeDefaultDescription
onlystring[]Only render specified fields
excludeRepeatersbooleanfalseSkip repeater fields
layout'stacked' | 'grid''stacked'Layout mode
columnsnumber1Grid columns (when layout='grid')
asstring'div'Root element tag
EventPayloadDescription
submitEventForm submission
input{ name, value }Field value changed
blur{ name }Field blurred
validate{ name, valid }Validation triggered

VormRepeater

Iterate over repeater fields:

vue
<VormRepeater name="contacts">
  <template #default="{ fullName, index, data, indexes }">
    <!-- Render repeater item -->
  </template>
</VormRepeater>
PropTypeDescription
namestringPath to repeater field
Slot PropTypeDescription
fullNamestringFull path (e.g., contacts[0])
indexnumberCurrent index
dataanyReactive reference to item data
indexesnumber[]Array of nesting indexes

VormSection

Groups related fields:

vue
<VormSection title="Account Info" :show-if="condition">
  <AutoVorm :only="['email', 'password']" />
</VormSection>
PropTypeDescription
titlestringSection heading
showIfboolean | (() => boolean)Conditional visibility

Utility Functions

Path Helpers

ts
import { getValueByPath, setValueByPath } from 'vorm-vue';

// Get nested value
const email = getValueByPath(formData, 'contacts[0].email');

// Set nested value
setValueByPath(formData, 'contacts[0].email', 'new@email.com');

useVormContext

Access vorm context in child components:

ts
import { useVormContext } from 'vorm-vue';

const vorm = useVormContext();
// Now you can access vorm.formData, vorm.errors, etc.

Slot API

Field Slots

Replace entire field rendering:

vue
<AutoVorm>
  <template #fieldName="{ field, state, path, indexes }">
    <!-- Custom field rendering -->
  </template>
</AutoVorm>

Wrapper Slots

Wrap default input:

vue
<AutoVorm>
  <!-- Specific field -->
  <template #wrapper:fieldName="slotProps">...</template>

  <!-- Multiple fields -->
  <template #wrapper:[fieldA,fieldB]="slotProps">...</template>

  <!-- Global fallback -->
  <template #wrapper="slotProps">...</template>
</AutoVorm>

Wrapper Slot Props

ts
{
  // Field info
  field: ResolvedVormFieldSchema;
  state: FieldState;
  path: string;
  indexes: number[];
  content: () => VNode;

  // Bindings for third-party components
  modelValue: any;
  'onUpdate:modelValue': (value: any) => void;
  items: Option[];
  options: Option[];
  error: string | undefined;
  errorMessages: string[];
}

Before/After Slots

vue
<AutoVorm>
  <template #before-fieldName>Content before</template>
  <template #after-fieldName>Content after</template>
</AutoVorm>

Nuxt Module

Installation

bash
pnpm add vorm-nuxt

Configuration

ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['vorm-nuxt'],
  vorm: {
    autoImports: true,   // Auto-import composables
    components: true,    // Auto-register components
  },
});

Auto-Imports

When autoImports: true:

  • useVorm
  • useVormContext
  • VormSchema (type)
  • VormFieldSchema (type)

Auto-Components

When components: true:

  • VormProvider
  • AutoVorm
  • VormRepeater
  • VormSection

MIT Licensed