InputfieldInteger
Integer input
Extends [[Inputfield]] directly (not InputfieldText). Accepts positive and negative integers; decimals and comma-formatted numbers are rounded to the nearest integer.
$f = $modules->get('InputfieldInteger');
$f->name = 'quantity';
$f->label = 'Quantity';
$f->min = 1;
$f->max = 100;
$form->add($f); [[InputfieldFloat]] extends this class and adds decimal support.
See [[Inputfield]] for the shared Inputfield API.
| Property | Type | Default | Description |
|---|---|---|---|
inputType | string | 'text' | Input type: 'text' or 'number' (HTML5 numeric input) |
min | int\|float | '' | Minimum allowed value; enforced when setting value attribute |
max | int\|float | '' | Maximum allowed value; enforced when setting value attribute |
step | int\|float | '' | HTML5 step attribute; only applied when inputType = 'number' |
size | int | 10 | Input size attribute; 0 renders full-width |
placeholder | string | '' | Input placeholder text |
initValue | int\|float | '' | Default value when used as a standalone Inputfield (not with a Fieldtype) |
defaultValue | int\|float | '' | Default value when used with [[FieldtypeInteger]] |
$f->inputType = 'text'; // plain text input — no browser numeric UI (default)
$f->inputType = 'number'; // HTML5 numeric input — browser adds up/down arrows,
// and min/max/step are enforced client-sideThe text type is the default because it avoids browser-specific numeric UI quirks.
Use number when you want native browser validation or the spinner UI.
min and max are enforced at the PHP level regardless of inputType. If a submitted
value falls outside the range, an error notice is added and the previous value is
restored.
$f->min = 0;
$f->max = 999;
$f->step = 5; // only affects the browser UI when inputType='number'isEmpty() returns true only when the value is an empty string — the integer 0
is considered a present, non-empty value:
$f->val(0); // isEmpty() → false
$f->val(''); // isEmpty() → trueOn input, the value is stripped of non-digit characters (except ., ,, and a
leading -). Decimals and comma-formatted numbers are rounded: 1,234.7 → 1235.
Negative numbers are preserved: -42 → -42.
- [[InputfieldFloat]] extends this class and overrides
sanitizeValue()andtypeValue()to allow decimal values. - Source file:
wire/modules/Inputfield/InputfieldInteger/Inputfield Integer.module
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield class also inherits all the methods and properties of: Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | int float string | Initial/default value (when used with FieldtypeInteger) DEFAULT: '' | |
| Inputfield | int float | Initial/default value (when used as independent Inputfield) DEFAULT: '' | |
| Inputfield | string | Input type to use, one of "text" or "number" DEFAULT: text | |
| Inputfield | int float | Maximum allowed value DEFAULT: '' | |
| Inputfield | int float | Minimum allowed value DEFAULT: '' | |
| Inputfield | string | Placeholder attribute value DEFAULT: '' | |
| Inputfield | int | Size attribute value DEFAULT: 10 | |
| Inputfield | int float string | HTML5 step attribute value DEFAULT: '' |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.267