Skip to content

Commit 335b909

Browse files
committed
[reference][forms] Adding the percent type
1 parent 6a87e04 commit 335b909

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

reference/forms/types/percent.rst

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,43 @@
44
``percent`` Field Type
55
======================
66

7-
See :class:`Symfony\\Component\\Form\\Type\\PercentType`.
7+
8+
The ``percent`` type renders an input text field and specializes in handling
9+
percentage data. If your percentage data is stored as a decimal (e.g. ``.95``),
10+
you can use this field out-of-the-box. If you store your data as a number
11+
(e.g. ``95``), you should set the ``type`` option to ``integer``.
12+
13+
This field adds a percentage sign "``%``" after the input box.
14+
15+
============ ======
16+
Rendered as ``input`` ``text`` field
17+
Options ``type``, ``required``, ``label``, ``read_only``, ``error_bubbling``
18+
Parent type ``field``
19+
Class :class:`Symfony\\Component\\Form\\Type\\PercentType`
20+
============ ======
21+
22+
Options
23+
-------
24+
25+
* ``type`` [type: string, default: ``fractional``]
26+
This controls how your data is stored on your object. For example, a percentage
27+
corresponding to "55%", might be stored as ``.55`` or ``55`` on your
28+
object. The two "types" handle these two cases:
29+
30+
* ``fractional``
31+
If your data is stored as a decimal (e.g. ``.55``), use this type.
32+
The data will be multiplied by ``100`` before being shown to the
33+
user (e.g. ``55``). The submitted data will be divided by ``100``
34+
on form submit so that the decimal value is stored (``.55``);
35+
* ``integer``
36+
If your data is stored as an integer (e.g. 55), then use this option.
37+
The raw value (``55``) is shown to the user and stored on your object.
38+
Note that this only works for integer values.
39+
40+
.. include:: /reference/forms/types/options/required.rst.inc
41+
42+
.. include:: /reference/forms/types/options/label.rst.inc
43+
44+
.. include:: /reference/forms/types/options/read_only.rst.inc
45+
46+
.. include:: /reference/forms/types/options/error_bubbling.rst.inc

0 commit comments

Comments
 (0)