Skip to content

ValidationField ​

Wraps a Flux form field and registers its own validation rules with the surrounding form. The field validates the value prop against the given rules and shows the first error (client- or server-side) as an error addition below the input.

The validation-key doubles as the identifier server errors are matched on, so use the backend field name (usually snake_case). Changing the field's value clears a lingering server error for that key.

Importing ​

ts
import { ValidationField } from '@basmilius/validation';

Usage ​

vue
<ValidationField
    label="Code"
    :rules="[rules.required, rules.minLength(3), rules.maxLength(64)]"
    validation-key="code"
    :value="form.code">
    <FluxFormInput v-model="form.code"/>
</ValidationField>

Rules are usually passed as an array; each rule provides its own name. An object form is also accepted when a custom key is needed:

vue
<ValidationField
    label="Code"
    :rules="{required: rules.required, exact: named('exact', value => value === 'expected')}"
    validation-key="code"
    :value="form.code">
    <FluxFormInput v-model="form.code"/>
</ValidationField>

Using the component without rules throws; wrap plain fields in FluxFormField instead.

Props ​

PropTypeDescription
currentLengthnumberForwarded to FluxFormField.
hintstringForwarded to FluxFormField.
isOptionalbooleanForwarded to FluxFormField.
labelstringThe field label. Required.
maxLengthnumberForwarded to FluxFormField.
rulesValidationRuleSetArray or record of rules. Required.
validationKeystringError key; matches the backend field name. Required.
valueunknownThe value to validate.

See also ​