Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81e3728

Browse filesBrowse files
peterrehmweaverryan
authored andcommitted
Added information about float choice lists
1 parent df16779 commit 81e3728
Copy full SHA for 81e3728

File tree

Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed

‎reference/forms/types/choice.rst

Copy file name to clipboardExpand all lines: reference/forms/types/choice.rst
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ is the item value and the array value is the item's label::
9393
'choices' => array('m' => 'Male', 'f' => 'Female')
9494
));
9595

96+
.. tip::
97+
98+
When the values to choose from are not integers or strings (but e.g. floats
99+
or booleans), you should use the `choice_list`_ option instead. With this
100+
option you are able to keep the original data format which is important
101+
to ensure that the user input is validated properly and useless database
102+
updates caused by a data type mismatch are avoided.
103+
96104
choice_list
97105
~~~~~~~~~~~
98106

@@ -103,6 +111,17 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
103111
For more advanced cases, a custom class that implements the interface
104112
can be created to supply the choices.
105113

114+
With this option you can also allow float values to be selected as data.
115+
116+
.. code-block:: php
117+
118+
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
119+
120+
// ...
121+
$builder->add('status', 'choice', array(
122+
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half')
123+
));
124+
106125
.. include:: /reference/forms/types/options/empty_value.rst.inc
107126

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.