Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One

Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createValidation

Per-field validation lifecycle composable. Manages validation state — errors, validity, pristine tracking — for individual fields. Works standalone or auto-registers with a parent createForm.


IntermediateMar 14, 2026

Usage

Standalone

Create a validation instance and register fields with rules:

ts
import { createValidation } from '@vuetify/v0'

const validation = createValidation()

const email = validation.register({
  id: 'email',
  value: '',
  rules: [
    v => !!v || 'Required',
    v => /^.+@\S+\.\S+$/.test(String(v)) || 'Invalid email',
  ],
})

await email.validate()

console.log(email.errors.value)    // ['Required']
console.log(email.isValid.value)   // false
console.log(email.isPristine.value) // true

email.reset()

With Rule Aliases

When a rules context is provided via createRulesPlugin or createRulesContext, alias strings resolve automatically:

ts
import { createValidation } from '@vuetify/v0'

const validation = createValidation()

const name = validation.register({
  id: 'name',
  value: '',
  rules: ['required', 'slug'],
})

With Standard Schema

Pass schema objects directly — they’re auto-detected and wrapped:

ts
import { z } from 'zod'
import { createValidation } from '@vuetify/v0'

const validation = createValidation()

const age = validation.register({
  id: 'age',
  value: '',
  rules: [z.coerce.number().int().min(18, 'Must be 18+')],
})

Auto-Registration with Forms

When created inside a component with a parent form context, createValidation auto-registers with the form. The form can then coordinate submit and reset across all registered validations. Cleanup happens automatically via onScopeDispose:

vue
<script setup lang="ts">
  import { createValidation } from '@vuetify/v0'

  // Parent provides form context via createFormContext or createFormPlugin
  // This validation auto-registers with it
  const validation = createValidation()

  const email = validation.register({
    id: 'email',
    value: '',
    rules: ['required', 'email'],
  })
</script>

Bulk Registration

Use onboard() to register multiple fields at once:

ts
const validation = createValidation()

const fields = validation.onboard([
  { id: 'name', value: '', rules: ['required'] },
  { id: 'email', value: '', rules: ['required', 'email'] },
  { id: 'bio', value: '', rules: [v => String(v).length <= 500 || 'Too long'] },
])

Silent Validation

Check validity without updating the UI:

ts
const valid = await email.validate(true) // silent = true
// email.errors.value is unchanged
// email.isValid.value is unchanged

Architecture

createValidation extends createRegistry with per-ticket validation state. When a parent form context exists, it auto-registers like a child component:

Validation Architecture

Use controls to zoom and pan. Click outside or press Escape to close.

Validation Architecture

Race Safety

Async validation uses a generation counter to prevent stale results. If a newer validation starts before an older one completes, the older result is discarded:

ts
// User types fast — each keystroke triggers validation
email.value = 'a'     // generation 1
email.value = 'ab'    // generation 2 — generation 1 result discarded
email.value = 'abc'   // generation 3 — generation 2 result discarded
// Only generation 3 result is applied

Reactivity

Field-level and aggregate state are fully reactive.

Property/MethodReactiveNotes
isValidComputed aggregate from all tickets
isValidatingComputed aggregate from all tickets
ticket.valueShallowRef, resets isValid on change
ticket.errorsShallowRef array
ticket.isValidShallowRef (null/true/false)
ticket.isPristineShallowRef boolean
ticket.isValidatingShallowRef boolean

API Reference

The following API details are for the createValidation composable.

Functions

createValidation

(options?: ValidationOptions) => R

Creates a new validation instance.

Options

events

boolean | undefined

Enable event emission for registry operations

Default: false

reactive

boolean | undefined

Enable reactive behavior for registry operations

Default: false

Properties

collection

ReadonlyMap<ID, E>

The collection of tickets in the registry

size

number

The number of tickets in the registry

isValid

ComputedRef<boolean | null>

Aggregate: true if all tickets valid, false if any invalid, null if any unvalidated.

isValidating

ComputedRef<boolean>

Aggregate: true if any ticket is validating.

Methods

clear

() => void

Clear the entire registry

has

(id: ID) => boolean

Check if a ticket exists by ID

keys

() => readonly ID[]

Get all registered IDs

browse

(value: E["value"]) => ID[] | undefined

Browse for an ID(s) by value

lookup

(index: number) => ID | undefined

lookup a ticket by index number

get

(id: ID) => E | undefined

Get a ticket by ID

upsert

(id: ID, ticket?: Partial<Z>) => E

Update or insert a ticket by ID

values

() => readonly E[]

Get all values of registered tickets

entries

() => readonly [ID, E][]

Get all entries of registered tickets

unregister

(id: ID) => void

Unregister a ticket by ID

reindex

() => void

Reset the index directory and update all tickets

move

(id: ID, toIndex: number) => E | undefined

Seek for a ticket based on direction and optional predicate

seek

(direction?: "first" | "last", from?: number, predicate?: (ticket) => boolean) => E | undefined

on

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<E, K>) => void

Listen for registry events

off

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<E, K>) => void

Stop listening for registry events

emit

<K extends Extensible<RegistryEventName>>(event: K, data: EventPayload<E, K>) => void

Emit an event with data

dispose

() => void

Clears the registry and removes all listeners

offboard

(ids: ID[]) => void

Offboard multiple tickets at once

batch

<R>(fn: () => R) => R

Execute operations in a batch, deferring cache invalidation and event emission until complete

register

(registration?: Partial<Z>) => E

onboard

(registrations: Partial<Z>[]) => E[]
Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/