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
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 is under validation. The value is represented using dot notation. For example: In the case of an array, the * symbol is used for children elements.


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. 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 know if the field is valid. It will be considered invalid if the field 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) {