react-formbridge
Browse documentation
Field buildersv1.0.2

field.number()

Numeric builder that stores a real number, not a string.

  • Numeric helpers live directly on the builder: positive(), nonNegative(), integer(), step()
  • min() / max() set numeric bounds (not character length like on string builders)
  • Inherits base builder methods but not string builder methods
Number.tsxtsx
1const schema = {
2 quantity: field.number('Quantity')
3 .required()
4 .positive()
5 .integer()
6 .step(5, 'Order in increments of 5'),
7}

Defaults, inheritance & field methods

  • defaultValue is 0
  • type is number
  • Shared methods: see Base field builder
  • String-specific helpers do not apply here; min() and max() operate on real numeric values

Number-specific methods:

MethodTypeDescription
min(value, message?)value: numberSets the minimum accepted numeric value.
max(value, message?)value: numberSets the maximum accepted numeric value.
positive(message?)message?: stringRequires a value strictly greater than zero.
nonNegative(message?)message?: stringRequires a value greater than or equal to zero.
integer(message?)message?: stringRestricts the value to whole numbers only.
gt(value, message?)value: numberStrict greater-than check against a static number.
gte(value, message?)value: numberGreater-than-or-equal check against a static number (inclusive lower bound).
lt(value, message?)value: numberStrict less-than check against a static number.
lte(value, message?)value: numberLess-than-or-equal check against a static number (inclusive upper bound).
between(min, max, message?)min: number, max: numberRequires the value to fall inside [min, max] (both bounds inclusive).
multipleOf(value, message?)value: numberRequires the value to be an exact multiple of another number. Throws a helper message if called with value <= 0.
greaterThan(valueOrRef, message?)number | string | FieldReferenceCross-field version of gt(). Accepts another field name or a ref() path so you can enforce rules like maxPrice > minPrice.
lowerThan(valueOrRef, message?)number | string | FieldReferenceCross-field version of lt(). Accepts another field name or a ref() path, e.g. ref('maxQuantity').
step(stepValue, message?)stepValue: numberRequires the value to be a clean multiple of the provided step. Thin alias over multipleOf() with a step-oriented default message.

Recipes

Patterns that showcase number-specific strengths.

Batch order in increments

BatchQuantity.tsxtsx
1const schema = {
2 quantity: field.number('Quantity')
3 .required()
4 .integer()
5 .positive()
6 .step(5, 'Order in multiples of 5'),
7}

Percentage slider

Discount.tsxtsx
1const schema = {
2 discount: field.number('Discount %')
3 .min(0)
4 .max(100)
5 .nonNegative()
6 .defaultValue(0),
7}

Seat limit with business rule

Seats.tsxtsx
1const schema = {
2 seats: field.number('Seats')
3 .integer()
4 .positive()
5 .validate((value) =>
6 value <= 500
7 ? null
8 : 'Maximum 500 seats per workspace.',
9 ),
10}

Price with two-decimal step

UnitPrice.tsxtsx
1const schema = {
2 unitPrice: field.number('Unit price')
3 .nonNegative()
4 .step(0.01, 'Use two decimal places.'),
5}