8000 improved description of choice_list option of Choice form type · symfony/symfony-docs@5bc5969 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bc5969

Browse files
author
azielinski
committed
improved description of choice_list option of Choice form type
1 parent f3cff0b commit 5bc5969

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

reference/forms/types/choice.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,27 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
111111
For more advanced cases, a custom class that implements the interface
112112
can be created to supply the choices.
113113

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

116116
.. code-block:: php
117117
118118
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
119119
120120
// ...
121121
$builder->add('status', 'choice', array(
122-
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half'))
122+
'choice_list' => new ChoiceList(array(1, 0.5, 0.1), array('Full', 'Half', 'Almost empty'))
123123
));
124124
125+
The ``status`` field created by the code above will be rendered as:
126+
127+
.. code-block:: html
128+
129+
<select name="status">
130+
<option value="0">Full</option>
131+
<option value="1">Half</option>
132+
<option value="2">Almost empty</option>
133+
</select>
134+
125135
.. include:: /reference/forms/types/options/empty_value.rst.inc
126136

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

0 commit comments

Comments
 (0)
0