Fields

Number

A number, with an optional range and step.
The number field in the admin

Example

cms/collections/products.ts
export const products = defineCollection({
  fields: {
    price: { type: "number", required: true, min: 0, step: 0.01 },
    rating: { type: "number", min: 1, max: 5, appearance: "stepper" },
    discount: { type: "number", min: 0, max: 100, step: 5, appearance: "slider" },
  },
});

A read returns a number:

product.price; // number
product.rating; // number | null | undefined

Render it

<p>{product.price.toLocaleString("en", { style: "currency", currency: "EUR" })}</p>
{product.rating && <p>{"★".repeat(product.rating)}</p>}

Appearance

appearance picks the input in the admin. The stored value is the same.

AppearanceInput
"input" (default)A text box with up and down arrows
"plain"A text box without buttons
"stepper"Minus and plus buttons beside the number
"slider"A slider. Needs min and max
The number-stepper field in the admin
The number-slider field in the admin

Options

The smallest value.The largest value.The value MUST be min (or 0) plus a whole number of steps, like the HTML step attribute. step: 0.01 allows two decimals.Shown in the empty input.The input in the admin. Default "input".