Skip to content

Commit e1f583b

Browse files
althausweaverryan
authored andcommitted
Added choices_as_values description
1 parent d3cf004 commit e1f583b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

reference/forms/types/choice.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ is the item's label and the array value is the item's value::
123123
able to use values that are not integers or strings (but e.g. floats
124124
or booleans).
125125

126+
choices_as_values
127+
~~~~~~~~~~~~~~~~~
128+
129+
**type**: ``boolean`` **default**: false
130+
131+
.. versionadded:: 2.7
132+
133+
The ``choices_as_values`` option of ChoiceType was introduced in Symfony 2.7.
134+
135+
The ``choices_as_values`` option was introduced to ensure backward compatibility with the
136+
modified handling of the ``choices`` optio. Being set to ``false`` the choices array
137+
will be read as values mapping the keys. Setting the option to ``true`` will enable the new
138+
handling of the choices mapping keys to values.
139+
140+
* Before 2.7::
141+
$builder->add('gender', 'choice', array(
142+
'choices' => array('m' => 'Male', 'f' => 'Female'),
143+
'choices_as_values' => false,
144+
));
145+
146+
* Optional since 2.7::
147+
$builder->add('gender', 'choice', array(
148+
'choices' => array('Male' => 'm', 'Female' => 'f'),
149+
'choices_as_values' => true,
150+
));
151+
152+
* Default for 3.0::
153+
$builder->add('gender', 'choice', array(
154+
'choices' => array('Male' => 'm', 'Female' => 'f'),
155+
));
156+
126157
.. caution::
127158

128159
The ``choices_as_values`` option will be removed in Symfony 3.0, where

0 commit comments

Comments
 (0)