Number
Numeric input with support for integers, decimals and min/max ranges.
Number fields collect numeric values with built-in validation for ranges, steps and decimal precision. They include spinner controls and only accept numeric input.
Basic Usage
Add a number field using the addNumber() builder method:
app/Models/Survey.php
Available Settings
Working with Decimals
Use the decimalPlaces() method to control decimal precision:
Step and Decimal Places
The
step setting controls the increment/decrement buttons, while decimal_places controls what values are accepted. Make sure they align (e.g., step: 0.01 with decimalPlaces: 2). Validation
Number fields are validated by the NumericFieldValidator, which checks:
- Value must be numeric
- Value must be within min/max range (if set)
- Value must match decimal_places precision
- Value must be a multiple of step (if set)
Frontend Behavior
- Shows numeric keyboard on mobile devices
- Increment/decrement buttons (up/down arrows) on desktop
- Prevents non-numeric characters (except decimal point when allowed)
- Arrow up/down keys adjust value by step amount
- Formats decimal places on blur
- Shows validation errors inline
Common Use Cases
Integers
Age, quantity, count, year
decimalPlaces(0) Money
Prices, salaries, costs
decimalPlaces(2), step(0.01) Percentages
Rates, completion, scores
min(0), max(100), decimalPlaces(1) Measurements
Height, weight, distance
decimalPlaces(1), step(0.1) Browser Support
Number field behavior varies across browsers. Some (like Firefox) allow non-numeric input and validate on submit, while others (like Chrome) block it entirely. Polyform's server-side validation ensures consistent behavior regardless.