Skip to content

DiscriminatedVariantFieldInput

Defined in: packages/core/src/fields/variant/types.ts:111

Configuration input for a DISCRIMINATED variant() field — an object union keyed by discriminator, storing v.union(v.object({ [discriminator]: v.literal(key), ...fields }), ...) (a single variant collapses to a bare v.object()). No id/blockName keys are injected — unlike blocks(), the stored shape is exactly the discriminator plus the variant’s own fields.

Defaults applied by variant():

{
type: "variant",
label: "",
required: false,
nullable: false,
admin: { display: "select", hidden: false, readOnly: false, position: "main", width: "100%", cellAlignment: "left" },
}
channel: variant({
label: "Notification channel",
discriminator: "kind",
variants: {
email: { label: "Email", fields: { address: text({ required: true }) } },
sms: { label: "SMS", fields: { phoneNumber: text({ required: true }) } },
},
})
  • Omit<BaseFieldInput<TCollectionSlug, TFieldKey, TFieldMeta>, "admin">

TCollectionSlug extends VexResourceSlug = VexResourceSlug

TFieldKey extends string = never

TFieldMeta extends object = { }

optional admin?: VariantFieldAdminInput<TCollectionSlug>

Defined in: packages/core/src/fields/variant/types.ts:116


optional defaultValue?: Record<string, unknown>

Defined in: packages/core/src/fields/variant/types.ts:127

Pre-filled value shown in the admin form when creating a new field. Does not apply to database values

RelationshipFieldInput.defaultValue


optional dependsOn?: readonly Exclude<FieldKeyOfResource<TCollectionSlug>, TFieldKey>[]

Defined in: packages/core/src/fields/baseTypes.ts:610

Other fields whose change re-runs THIS field’s validate() on a partial write (update/saveDraft) — core already runs validate() when the field’s OWN key changed; dependsOn adds more keys that also trigger it. validate() still only receives and reports on this field’s own key/value — dependsOn only widens WHEN it runs, never what it validates. Has no effect on the strict pass (publish/create): every field’s own key is already in that pass’s changed set, so dependsOn there is purely redundant, never exclusionary.

Resolved against the collection’s/global’s own top-level field keys — the same universe index’s additionalFields checks against — and validated at defineCollection/defineGlobal time: an unknown key throws VexConfigError. Declaring it on a field nested inside a group()/array()/blocks() is accepted by the type system (every field type shares this base) but has no runtime effect: validateFields only ever runs a TOP-LEVEL field’s own validate() (see fields/validate.ts), so a nested field’s validate()/dependsOn never individually runs regardless.

endDate: date({
dependsOn: ["startDate"],
validate: dateValidator<typeof TABLE_SLUG_EVENTS>(
TABLE_SLUG_EVENTS,
({ value, doc }) => {
if (typeof doc.startDate === "number" && typeof value === "number" && value <= doc.startDate) {
throw new VexError({ message: "End date must be after the start date." });
}
},
),
})

Omit.dependsOn


optional description?: string

Defined in: packages/core/src/fields/baseTypes.ts:534

Semantic description of the field. Used in three places:

  1. Helper text rendered below the field input in the admin form UI.
  2. As the Zod .meta({ description }) value for form validation.
  3. As the JSDoc comment on the generated document interface property.

To write a separate JSDoc comment, use interfaceDescription in addition.

UploadFieldInput.description


discriminator: string

Defined in: packages/core/src/fields/variant/types.ts:118

Property name stored on every variant, naming which one is active.


optional index?: FieldIndexConfigInput<TCollectionSlug, TFieldKey>

Defined in: packages/core/src/fields/baseTypes.ts:573

Create a database index on this field. The string value becomes the index name in Convex.

slug: { type: "text", index: "by_slug", required: true }
// Generates: .index("by_slug", ["slug"])
author: { type: "relationship", index: { name: "by_author_status", additionalFields: ["status"] } }
// Generates: .index("by_author_status", ["author", "status"])

Omit.index


optional interfaceDescription?: string

Defined in: packages/core/src/fields/baseTypes.ts:536

The JSDoc comment on the generated document interface property

UploadFieldInput.interfaceDescription


optional interfaceName?: string

Defined in: packages/core/src/fields/variant/types.ts:126

Optional TypeScript union alias name. When set, emits export type NotificationChannel = { kind: "email"; ... } | { kind: "sms"; ... } and the collection interface uses the alias instead of the inline union.


optional label?: string

Defined in: packages/core/src/fields/baseTypes.ts:525

Display label for the field in the admin form.

UploadFieldInput.label


optional meta?: TFieldMeta

Defined in: packages/core/src/fields/baseTypes.ts:574

Omit.meta


optional nullable?: boolean

Defined in: packages/core/src/fields/baseTypes.ts:552

Whether null is a legal value for this field, in addition to its normal type. required: true emits v.nullable(X); required: false emits v.optional(v.nullable(X)). Clearing the field’s input (or, for a container/checkbox field with no natural empty state, its FormFieldLayout null toggle) writes null.

Default: false

UploadFieldInput.nullable


optional required?: boolean

Defined in: packages/core/src/fields/baseTypes.ts:542

Whether this field is required.

Default: false

UploadFieldInput.required


variants: Record<string, VariantMemberInput>

Defined in: packages/core/src/fields/variant/types.ts:120

One entry per variant, keyed by its stored discriminant value.

optional validate(props): void | Promise<void>

Defined in: packages/core/src/fields/variant/types.ts:129

Server-only async validation with value typed as the stored object.

FieldValidateProps<TCollectionSlug, Record<string, unknown>>

void | Promise<void>

FieldValidate

Omit.validate