useValidation

Commons
stable

Full validation engine for form field components. Runs async rule functions, accumulates error messages, tracks pristine / dirty / disabled / readonly states, and integrates with a parent OrigamForm (via ORIGAM_FORM_KEY injection) for coordinated validate / reset / resetValidation calls.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useValidation auto-registers the field with a parent OrigamForm on beforeMount and unregisters on beforeUnmount. The form can then call `form.validate()` to trigger all registered fields at once.

Interfaces consommées

IValidationProps

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

props
requis
IValidationProps
Props read: modelValue, validationValue, rules, error, errorMessages, maxErrors, disabled, readonly, focused, validateOn, name.
name
string
getCurrentInstanceName()
Component name prefix for validation CSS class names (e.g. `origam-text-field--error`).
id
MaybeRef<string | number>
getUid()
Unique field ID used to register with the parent form. Defaults to an auto-generated UID.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

errorMessages
Merged list of external `props.errorMessages` and internally computed rule failures, capped at `maxErrors`.
isDirty
True when the model value (or validationValue) is non-empty. Drives the "dirty" modifier class.
isDisabled
True when `props.disabled` or the parent form is disabled.
isReadonly
True when `props.readonly` or the parent form is readonly.
isPristine
True until the first validation run that is not silent. Reset by resetValidation().
isValid
False when there are errors, undefined while pristine with a lazy strategy, true otherwise.
isValidating
True while async rule functions are running.
reset
Clear the model value (set to null), then run resetValidation.
resetValidation
Mark as pristine and clear internal error messages without changing the value.
validate
Run all rule functions and return the list of error messages. When silent=true, isPristine stays true (used for initial validation on mount).
validationClasses
Computed class map with `--error`, `--dirty`, `--disabled`, `--readonly` modifier classes.

Usage

Exemples

Extraits de code prêts à coller.

Custom field with validation

vue