@vinejs/vine - v4.2.0
    Preparing search index...

    Class OptionalModifier<Schema>

    Modifies a literal schema type to allow undefined values in addition to the original type. This modifier is used for form fields that may not be present in submitted data.

    const schema = vine.string().optional()
    // Accepts: "hello", undefined
    // Rejects: null (unless also nullable), 123

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    isOptional: boolean = true
    "[ITYPE]": Schema[typeof ITYPE] | null | undefined

    Define the input type of the schema, including undefined and null

    "[OTYPE]": Schema[typeof OTYPE] | undefined

    The output value of the field with undefined support. The property points to a type only and not the real value.

    "[COTYPE]": Schema[typeof COTYPE] | undefined

    Camelcase output type with undefined support

    validations: Validation<any>[]

    List of additional validations to apply to non-undefined values

    Accessors

    Methods

    • Marks the field as required when a condition is met. Can be used with a callback or with comparison operators to compare another field's value.

      Type Parameters

      Parameters

      • otherField: string

        Field name to compare or callback function

      • operator: Operator

        Comparison operator (=, !=, in, notIn, >, <, >=, <=)

      • expectedValue: Operator extends ArrayComparisonOperators
            ? (string | number | boolean)[]
            : Operator extends NumericComparisonOperators
                ? number
                : string
                | number
                | boolean

        Expected value to compare against

      Returns this

      vine.string().optional().requiredWhen('role', '=', 'admin')
      
      vine.string().optional().requiredWhen('age', '>', 18)
      
      vine.string().optional().requiredWhen((field) => field.data.isAdmin === true)
      
    • Marks the field as required when a condition is met. Can be used with a callback or with comparison operators to compare another field's value.

      Parameters

      • callback: (field: FieldContext) => boolean

      Returns this

      vine.string().optional().requiredWhen('role', '=', 'admin')
      
      vine.string().optional().requiredWhen('age', '>', 18)
      
      vine.string().optional().requiredWhen((field) => field.data.isAdmin === true)