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
Full TypeScript signature sourced from the composable file.
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.
Consumed interfaces
IValidationProps
API
Parameters
Input parameters accepted by this composable.
- propsrequiredIValidationProps
- Props read: modelValue, validationValue, rules, error, errorMessages, maxErrors, disabled, readonly, focused, validateOn, name.
- namestringgetCurrentInstanceName()
- Component name prefix for validation CSS class names (e.g. `origam-text-field--error`).
- idMaybeRef<string | number>getUid()
- Unique field ID used to register with the parent form. Defaults to an auto-generated UID.
API
Return values
Properties and methods exposed by the composable return object.
- 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
Examples
Ready-to-paste usage snippets.
Custom field with validation