S
Documentation

Number

A numeric input field for collecting integer or decimal values such as age, quantity, or scores.

Schema Example

numberjson
{
  id: "age",
  type: "number",
  label: "What is your age?",
  placeholder: "Enter your age",
  required: true
}

Available Options

PropertyTypeDescription
labelstringThe question text displayed to the user.
placeholderstringPlaceholder text shown inside the input.
requiredbooleanWhether the field must be filled in.
defaultValuenumberPre-filled default numeric value.
descriptionstringOptional helper text displayed below the label.
visibleIfstringConditional expression to show/hide this question.
validationValidationRule[]Validation rules (min, max, required, custom, etc.).

With Validation

Number with min/max validationjson
{
  id: "age",
  type: "number",
  label: "Your age",
  required: true,
  validation: [
    { type: "min", value: 1, message: "Must be at least 1" },
    { type: "max", value: 120, message: "Must be at most 120" }
  ]
}

Answer Format

Returns a string value from the input. Use your own parsing if you need a numeric type.

Practical Example

Advanced Example

An order form that collects quantity with min/max constraints:

OrderForm.tsxtsx
import { SurveyRenderer } from 'react-minimal-survey-builder';
import type { SurveySchema } from 'react-minimal-survey-builder';

const orderSchema: SurveySchema = {
  id: 'order-form',
  title: 'Place Your Order',
  pages: [
    {
      id: 'order',
      questions: [
        {
          id: 'product',
          type: 'select',
          label: 'Product',
          required: true,
          options: [
            { label: 'Widget A', value: 'widget-a' },
            { label: 'Widget B', value: 'widget-b' },
          ],
        },
        {
          id: 'quantity',
          type: 'number',
          label: 'Quantity',
          placeholder: 'How many?',
          required: true,
          validation: [
            { type: 'min', value: 1, message: 'Minimum order is 1' },
            { type: 'max', value: 500, message: 'Maximum order is 500' },
          ],
        },
        {
          id: 'discount-code',
          type: 'text',
          label: 'Discount code',
          placeholder: 'Optional',
        },
      ],
    },
  ],
  settings: { submitText: 'Place Order' },
};

function OrderForm() {
  return (
    <SurveyRenderer
      schema={orderSchema}
      options={{
        onSubmit: async (answers) => {
          const qty = Number(answers.quantity);
          console.log('Order placed:', { ...answers, quantity: qty });
        },
      }}
    />
  );
}