integer Field Type

Renders an input “number” field. Basically, this is a text field that’s good at handling data that’s in an integer form. The input number field looks like a text box, except that - if the user’s browser supports HTML5 - it will have some extra frontend functionality.

This field has different options on how to handle input values that aren’t integers. By default, all non-integer values (e.g. 6.78) will round down (e.g. 6).

Rendered as input text field
Options
Inherited options
Parent type field
Class Symfony\Component\Form\Extension\Core\Type\IntegerType

Field Options

rounding_mode

type: integer default: IntegerToLocalizedStringTransformer::ROUND_DOWN

By default, if the user enters a non-integer number, it will be rounded down. There are several other rounding methods, and each is a constant on the Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer:

  • IntegerToLocalizedStringTransformer::ROUND_DOWN Rounding mode to round towards zero.
  • IntegerToLocalizedStringTransformer::ROUND_FLOOR Rounding mode to round towards negative infinity.
  • IntegerToLocalizedStringTransformer::ROUND_UP Rounding mode to round away from zero.
  • IntegerToLocalizedStringTransformer::ROUND_CEILING Rounding mode to round towards positive infinity.

grouping

type: integer default: false

This value is used internally as the NumberFormatter::GROUPING_USED value when using PHP’s NumberFormatter class. Its documentation is non-existent, but it appears that if you set this to true, numbers will be grouped with a comma or period (depending on your locale): 12345.123 would display as 12,345.123.

Inherited options

These options inherit from the field type:

required

type: Boolean default: true

If true, an HTML5 required attribute will be rendered. The corresponding label will also render with a required class.

This is superficial and independent from validation. At best, if you let Symfony guess your field type, then the value of this option will be guessed from your validation information.

label

type: string default: The label is “guessed” from the field name

Sets the label that will be used when rendering the field. The label can also be directly set inside the template:

{{ form_label(form.name, 'Your name') }}

read_only

type: Boolean default: false

If this option is true, the field will be rendered with the disabled attribute so that the field is not editable.

error_bubbling

type: Boolean default: false

If true, any errors for this field will be passed to the parent field or form. For example, if set to true on a normal field, any errors for that field will be attached to the main form, not to the specific field.