Skip to content

Commit 68db46c

Browse files
committed
feature #5428 Improved description of choice_list option (adamziel, javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Improved description of choice_list option | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | - Commits ------- 381720b Completed the explanation as suggested by Ryan 5bc5969 improved description of choice_list option of Choice form type
2 parents 02b9968 + 381720b commit 68db46c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

reference/forms/types/choice.rst

+16-2
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,31 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
109109
For more advanced cases, a custom class that implements the interface
110110
can be created to supply the choices.
111111

112-
With this option you can also allow float values to be selected as data.
112+
With this option you can also allow float values to be selected as data. For example:
113113

114114
.. code-block:: php
115115
116116
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
117117
118118
// ...
119119
$builder->add('status', 'choice', array(
120-
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half'))
120+
'choice_list' => new ChoiceList(array(1, 0.5, 0.1), array('Full', 'Half', 'Almost empty'))
121121
));
122122
123+
The ``status`` field created by the code above will be rendered as:
124+
125+
.. code-block:: html
126+
127+
<select name="status">
128+
<option value="0">Full</option>
129+
<option value="1">Half</option>
130+
<option value="2">Almost empty</option>
131+
</select>
132+
133+
But don't be confused! If ``Full`` is selected (value ``0`` in HTML), ``1`` will
134+
be returned in your form. If ``Almost empty`` is selected (value ``2`` in HTML),
135+
``0.1`` will be returned.
136+
123137
.. include:: /reference/forms/types/options/empty_value.rst.inc
124138

125139
.. include:: /reference/forms/types/options/expanded.rst.inc

0 commit comments

Comments
 (0)