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.

Properties
PropertyTypeDefaultDescription
inputTypestring'text'Input type: 'text' or 'number' (HTML5 numeric input)
minint\|float''Minimum allowed value; enforced when setting value attribute
maxint\|float''Maximum allowed value; enforced when setting value attribute
stepint\|float''HTML5 step attribute; only applied when inputType = 'number'
sizeint10Input size attribute; 0 renders full-width
placeholderstring''Input placeholder text
initValueint\|float''Default value when used as a standalone Inputfield (not with a Fieldtype)
defaultValueint\|float''Default value when used with [[FieldtypeInteger]]
Input type
$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-side

The 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.

Range and step

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'
Empty vs. zero

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() → true
Sanitization

On input, the value is stripped of non-digit characters (except ., ,, and a leading -). Decimals and comma-formatted numbers are rounded: 1,234.71235. Negative numbers are preserved: -42-42.

Notes
  • [[InputfieldFloat]] extends this class and overrides sanitizeValue() and typeValue() to allow decimal values.
  • Source file: wire/modules/Inputfield/InputfieldInteger/InputfieldInteger.module
API reference: methods, properties, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the InputfieldInteger class also inherits all the methods and properties of: Inputfield, WireData and Wire.

Show class?     Show args?       Only hookable?    

Properties

NameReturnSummary 
InputfieldInteger::defaultValue int float string Initial/default value (when used with FieldtypeInteger)
DEFAULT: ''
 
InputfieldInteger::initValue int float Initial/default value (when used as independent Inputfield)
DEFAULT: ''
 
InputfieldInteger::inputType string Input type to use, one of "text" or "number"
DEFAULT: text
 
InputfieldInteger::max int float Maximum allowed value
DEFAULT: ''
 
InputfieldInteger::min int float Minimum allowed value
DEFAULT: ''
 
InputfieldInteger::placeholder string Placeholder attribute value
DEFAULT: ''
 
InputfieldInteger::size int Size attribute value
DEFAULT: 10
 
InputfieldInteger::step int float string HTML5 step attribute value
DEFAULT: ''
 

Additional methods and properties

In addition to the methods and properties above, InputfieldInteger also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.267