Skip to content

number

number<TFieldMeta>(options?): NumberField<TFieldMeta>

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

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)
  • requiredfalse
  • admin.hiddenfalse
  • admin.readOnlyfalse
  • admin.position"main"
  • admin.width"full"
  • admin.cellAlignment"left"

TFieldMeta extends object = { }

NumberFieldInput<TFieldMeta>

Number field configuration. All properties are optional.

NumberField<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: { value: 1 }, index: "by_quantity" }),
// Rating capped between 0 and 5
rating: number({
min: { value: 0, error: "Rating cannot be negative" },
max: { value: 5, error: "Rating cannot exceed 5" },
admin: { width: "half" },
}),
}
})