KeyValueFieldInput
Defined in: packages/core/src/fields/keyValue/types.ts:93
Configuration input for a keyValue() field.
KeyValue fields store a Convex v.record(keys, value) — a dynamically-keyed
map from keys (v.string() by default, or v.id(collection) when keys
is set) to one shared value data field, which may itself be any data
field including containers (group(), array(), nested keyValue()).
A fixed, literal key set is a group(), not this field.
Defaults applied by keyValue():
{ type: "keyValue", label: "", required: false, defaultValue: {}, admin: { hidden: false, readOnly: false, position: "main", width: "100%", cellAlignment: "left", defaultCollapsed: false, }}Example
Section titled “Example”scores: keyValue({ label: "Scores", value: number({ required: true }) })
userScores: keyValue({ label: "User Scores", keys: { collection: { slug: "user" } }, value: number({ required: true }),})- KeyValueField for the resolved output type
- keyValue for the config function that produces this type
Extends
Section titled “Extends”BaseFieldInput<TCollectionSlug,TFieldKey,TFieldMeta>
Type Parameters
Section titled “Type Parameters”TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends VexResourceSlug = VexResourceSlug
TFieldKey
Section titled “TFieldKey”TFieldKey extends string = never
TFieldMeta
Section titled “TFieldMeta”TFieldMeta extends object = { }
TKeysSlug
Section titled “TKeysSlug”TKeysSlug extends CollectionSlug = CollectionSlug
Properties
Section titled “Properties”admin?
Section titled “admin?”
optionaladmin?:KeyValueFieldAdminConfigInput<TCollectionSlug>
Defined in: packages/core/src/fields/keyValue/types.ts:99
Admin UI configuration for this field.
Overrides
Section titled “Overrides”defaultValue?
Section titled “defaultValue?”
optionaldefaultValue?:Record<string,unknown>
Defined in: packages/core/src/fields/keyValue/types.ts:109
Pre-filled value shown when creating a new document. Defaults to {}.
Overrides
Section titled “Overrides”dependsOn?
Section titled “dependsOn?”
optionaldependsOn?: readonlyExclude<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.
Example
Section titled “Example”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." }); } }, ),})Inherited from
Section titled “Inherited from”description?
Section titled “description?”
optionaldescription?:string
Defined in: packages/core/src/fields/baseTypes.ts:534
Semantic description of the field. Used in three places:
- Helper text rendered below the field input in the admin form UI.
- As the Zod
.meta({ description })value for form validation. - As the JSDoc comment on the generated document interface property.
To write a separate JSDoc comment, use interfaceDescription in addition.
Inherited from
Section titled “Inherited from”index?
Section titled “index?”
optionalindex?: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.
Example
Section titled “Example”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"])Inherited from
Section titled “Inherited from”interfaceDescription?
Section titled “interfaceDescription?”
optionalinterfaceDescription?:string
Defined in: packages/core/src/fields/baseTypes.ts:536
The JSDoc comment on the generated document interface property
Inherited from
Section titled “Inherited from”BaseFieldInput.interfaceDescription
optionalkeys?:KeyValueFieldKeysInput<TKeysSlug>
Defined in: packages/core/src/fields/keyValue/types.ts:101
Record key target. Omit for v.string() keys (the default).
label?
Section titled “label?”
optionallabel?:string
Defined in: packages/core/src/fields/baseTypes.ts:525
Display label for the field in the admin form.
Inherited from
Section titled “Inherited from”
optionalmeta?:TFieldMeta
Defined in: packages/core/src/fields/baseTypes.ts:574
Inherited from
Section titled “Inherited from”nullable?
Section titled “nullable?”
optionalnullable?: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
Inherited from
Section titled “Inherited from”required?
Section titled “required?”
optionalrequired?:boolean
Defined in: packages/core/src/fields/baseTypes.ts:542
Whether this field is required.
Default: false
Inherited from
Section titled “Inherited from”value:
AdminDataField
Defined in: packages/core/src/fields/keyValue/types.ts:107
The ONE data field every record entry’s value is validated against.
Record values can’t be v.optional in Convex — keyValue() forces this
field’s own required to true; its nullable still applies.
Methods
Section titled “Methods”validate()?
Section titled “validate()?”
optionalvalidate(props):void|Promise<void>
Defined in: packages/core/src/fields/keyValue/types.ts:111
Server-only async validation with value typed as Record<string, unknown>.
Parameters
Section titled “Parameters”FieldValidateProps<TCollectionSlug, Record<string, unknown>>
Returns
Section titled “Returns”void | Promise<void>
Overrides
Section titled “Overrides”BaseFieldInput.validate