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

    Function group

    • Creates an object group that conditionally merges properties into an existing object based on runtime validation logic. Groups enable dynamic schema composition where different properties are required based on conditional rules.

      Type Parameters

      Parameters

      • conditionals: Conditional[]

        Array of conditional property sets to evaluate

      Returns ObjectGroup<Conditional>

      ObjectGroup instance that can be merged into a VineObject

      const schema = vine.object({
      account_type: vine.string()
      }).merge(
      vine.group([
      vine.group.if((value) => value.account_type === 'personal', {
      first_name: vine.string(),
      last_name: vine.string()
      }),
      vine.group.if((value) => value.account_type === 'business', {
      company_name: vine.string(),
      tax_id: vine.string()
      })
      ])
      )
    Index

    Methods

    Methods

    • Wraps object properties inside a conditional statement that evaluates at validation time. Properties are only validated and merged if the condition returns a truthy value.

      Type Parameters

      Parameters

      • conditon: (value: Record<string, unknown>, field: FieldContext) => any

        Callback function that receives the object value and field context

      • properties: Properties

        Properties to merge when the condition is truthy

      Returns GroupConditional<
          Properties,
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol]: Properties[K][typeof ITYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol]: Properties[K][typeof ITYPE]
                      }[K]
                  }
              )[K]
          },
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol]: Properties[K][typeof OTYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol]: Properties[K][typeof OTYPE]
                      }[K]
                  }
              )[K]
          },
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol as CamelCase<K & string>]: Properties[K][typeof COTYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol as CamelCase<K & string>]: Properties[K][typeof COTYPE]
                      }[K]
                  }
              )[K]
          },
      >

      GroupConditional instance for use in vine.group()

      vine.group([
      vine.group.if(
      (value) => value.type === 'admin',
      {
      permissions: vine.array(vine.string()),
      access_level: vine.number()
      }
      ),
      vine.group.if(
      (value) => value.type === 'user',
      {
      username: vine.string()
      }
      )
      ])
    • Wraps object properties inside an "else" condition that always evaluates to true. Use this as a fallback when no other conditions in the group match.

      Type Parameters

      Parameters

      • properties: Properties

        Properties to merge when no other condition matches

      Returns GroupConditional<
          Properties,
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol]: Properties[K][typeof ITYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol]: Properties[K][typeof ITYPE]
                      }[K]
                  }
              )[K]
          },
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol]: Properties[K][typeof OTYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol]: Properties[K][typeof OTYPE]
                      }[K]
                  }
              )[K]
          },
          {
              [K in string
              | number
              | symbol]: (
                  {
                      [K in string
                      | number
                      | symbol]?: {
                          [K in string | number | symbol as CamelCase<K & string>]: Properties[K][typeof COTYPE]
                      }[K]
                  } & {
                      [K in string
                      | number
                      | symbol]: {
                          [K in string | number | symbol as CamelCase<K & string>]: Properties[K][typeof COTYPE]
                      }[K]
                  }
              )[K]
          },
      >

      GroupConditional instance that always matches

      vine.group([
      vine.group.if((value) => value.role === 'admin', {
      admin_key: vine.string()
      }),
      vine.group.else({
      user_key: vine.string()
      })
      ])