File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ is the item value and the array value is the item's label::
93
93
'choices' => array('m' => 'Male', 'f' => 'Female')
94
94
));
95
95
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
+
96
104
choice_list
97
105
~~~~~~~~~~~
98
106
@@ -103,6 +111,17 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
103
111
For more advanced cases, a custom class that implements the interface
104
112
can be created to supply the choices.
105
113
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
+
106
125
.. include :: /reference/forms/types/options/empty_value.rst.inc
107
126
108
127
.. include :: /reference/forms/types/options/expanded.rst.inc
You can’t perform that action at this time.
0 commit comments