Field context

Field context

Field context refers to the field object you may access inside the validation functions, union conditionals, the parse method, or the transform method.

The field object provides information about the current field under validation and access to the global data object and parent objects/arrays (if any).

Following is the list of available properties.

type FieldContext = {
value: unknown
data: any
meta: Record<string, any>
wildCardPath: string
isValid: boolean
isDefined: boolean
getFieldPath(): string
mutate(newValue: any, field: FieldContext): void
message: string,
rule: string,
field: FieldContext,
args?: Record<string, any>
): void
parent: any
name: string | number
isArrayMember: boolean


The value of the field under validation.


The root data object under validation. This is a shared property across all the fields, so do not mutate the object.


The meta object is a shared property across all the fields. You may use this property to pass metadata across fields or rules.


The nested path to the field under validation. The value is represented using dot notation. For example: In the case of an array, the * symbol is used for children elements.


Returns the nested path to a field. This method is different from the wildCardPath property since, in the case of arrays, the getFieldPath method will return a complete path with the runtime value of the current index. For example:

// Given the following schema
const schema = vine.object({
contacts: vine.array(
email: vine.string()
* The return value of "getFieldPath" will be
* - ""
* - ""
* - and so on
* The value of "wildCardPath" will be
* - "contacts.*.email"


A function to mutate the value of the field. This function must be used by validation rules, not union conditionals or the transform method.

vine.createRule((value, options, field) => {
* Mutate output value. The next validation rule will receive
* the updated value
field.mutate(value.toUpperCase(), field)


A method to report error messages for a specific field. The method accepts the following arguments.

  • The default message to display when a custom error message is not defined.
  • The name of the validation rule for which the validation failed.
  • Reference to the current field object.
  • Optional metadata to share with the error reporter.
vine.createRule((value, options, field) => {'error message', 'error_id', field, {
key: 'value'


A boolean to determine if the field is valid. It will be considered invalid if it has failed one or more validations.


A boolean to know if the field is defined. Fields with null or undefined values are considered undefined.


Reference to the parent object or array (if the field is nested). Otherwise, the parent property refers to the data object.


The name of the field under validation. In the case of an array element, it will be the array index.


A boolean to know if the field is an array element. When set to true, the value of name will be the array index, and the parent property will be an array (otherwise object).

vine.createRule((value, options, field) => {
if (field.isArrayMember) {