Skip to main content

Number

Number widgetNumber widget

Integer input - digits with an optional leading minus. It collects an int.

$p->number('weight', 'Basket weight (g)')
->min(200) // Lowest accepted value, inclusive.
->max(9000) // Highest accepted value, inclusive.
->step(100) // Amount the Up/Down keys adjust by.
->default(1200); // Initial value.

Runnable script: playground/02-widgets/number.php.

Options

NameDescriptionRequiredDefault
min()Lowest accepted value, inclusive.NoUnbounded
max()Highest accepted value, inclusive.NoUnbounded
step()Amount the Up/Down keys adjust by; must be positive.No1
default()Initial value.No0

With no bounds declared the field is a plain integer entry and the arrow keys are inert. Declaring min(), max() or step() turns on Up/Down adjustment; the value is clamped only when a range (min() / max()) is set.

Keyboard

KeyAction
digitsInsert a digit
-Leading minus (once, at the start)
/ Move the caret
/ Increment / decrement by step (only when bounds are set)
EnterAccept (an out-of-range value is rejected inline)
EscCancel

Headless behaviour

The bounds are enforced when the form runs headlessly too - a value outside the range is rejected - and surface in the JSON schema as min, max and step on the prompt.

Display modes

In all four display modes - Unicode or ASCII, colour on or off:

ANSINo ANSI
UnicodeNumber: Unicode + ANSINumber: Unicode + ANSINumber: Unicode + No ANSINumber: Unicode + No ANSI
ASCIINumber: ASCII + ANSINumber: ASCII + ANSINumber: ASCII + No ANSINumber: ASCII + No ANSI