Skip to content

number

number<TCollectionSlug, TFieldKey, TFieldMeta>(options?): NumberField<TCollectionSlug, TFieldMeta>

Defined in: packages/core/src/fields/number/config.ts:52

Creates a number field with all defaults applied.

Number fields store numeric values. Common uses: prices, quantities, ratings, ages, counts.

Accepts NumberFieldInput (all optional) and returns NumberField with all defaults applied.

Defaults applied:

  • label — "" (inferred from the field key by defineCollection)
  • required — false
  • admin.hidden — false
  • admin.readOnly — false
  • admin.position — "main"
  • admin.width — "100%"
  • admin.cellAlignment — "left"
  • admin.mask — not set (opt-in; no project-wide default applies unless configured)

TCollectionSlug extends string = string

TFieldKey extends string = never

TFieldMeta extends object = { }

NumberFieldInput<TCollectionSlug, TFieldKey, TFieldMeta>

Number field configuration. All properties are optional.

NumberField<TCollectionSlug, TFieldMeta>

Resolved number field definition with all defaults applied.

import { number, defineCollection } from '@vexcms/core'
products: defineCollection({
fields: {
// Minimal — label inferred from key ("Price")
price: number(),
// Required quantity with a minimum of 1 and a database index
quantity: number({ required: true, min: 1, index: "by_quantity" }),
// Rating capped between 0 and 5
rating: number({
min: [0, "Rating cannot be negative"],
max: [5, "Rating cannot exceed 5"],
admin: { width: "50%" },
}),
}
})