@@ -13,19 +13,19 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
13
13
| Rendered as | can be various tags (see below) |
14
14
+-------------+------------------------------------------------------------------------------+
15
15
| Options | - `choices `_ |
16
- | | - `choices_as_values `_ |
17
- | | - `choice_loader `_ |
18
- | | - `choice_label `_ |
19
16
| | - `choice_attr `_ |
17
+ | | - `choice_label `_ |
18
+ | | - `choice_list `_ (deprecated) |
19
+ | | - `choice_loader `_ |
20
+ | | - `choice_name `_ |
20
21
| | - `choice_translation_domain `_ |
21
- | | - `placeholder `_ |
22
+ | | - `choice_value `_ |
23
+ | | - `choices_as_values `_ |
22
24
| | - `expanded `_ |
25
+ | | - `group_by `_ |
23
26
| | - `multiple `_ |
27
+ | | - `placeholder `_ |
24
28
| | - `preferred_choices `_ |
25
- | | - `group_by `_ |
26
- | | - `choice_value `_ |
27
- | | - `choice_name `_ |
28
- | | - `choice_list `_ (deprecated) |
29
29
+-------------+------------------------------------------------------------------------------+
30
30
| Overridden | - `compound `_ |
31
31
| options | - `empty_data `_ |
@@ -172,6 +172,73 @@ is the item's label and the array value is the item's value::
172
172
'choices_as_values' => true,
173
173
));
174
174
175
+ .. include :: /reference/forms/types/options/choice_attr.rst.inc
176
+
177
+ .. _reference-form-choice-label :
178
+
179
+ .. include :: /reference/forms/types/options/choice_label.rst.inc
180
+
181
+ choice_list
182
+ ~~~~~~~~~~~
183
+
184
+ .. caution ::
185
+
186
+ The ``choice_list `` option of ChoiceType was deprecated in Symfony 2.7.
187
+ You should use `choices `_ or `choice_loader `_ now.
188
+
189
+ **type **: :class: `Symfony\\ Component\\ Form\\ Extension\\ Core\\ ChoiceList\\ ChoiceListInterface `
190
+
191
+ This is one way of specifying the options to be used for this field.
192
+ The ``choice_list `` option must be an instance of the ``ChoiceListInterface ``.
193
+ For more advanced cases, a custom class that implements the interface
194
+ can be created to supply the choices.
195
+
196
+ With this option you can also allow float values to be selected as data.
197
+ For example::
198
+
199
+ use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
200
+
201
+ // ...
202
+ $builder->add('status', 'choice', array(
203
+ 'choice_list' => new ChoiceList(
204
+ array(1, 0.5, 0.1),
205
+ array('Full', 'Half', 'Almost empty')
206
+ )
207
+ ));
208
+
209
+ The ``status `` field created by the code above will be rendered as:
210
+
211
+ .. code-block :: html
212
+
213
+ <select name =" status" >
214
+ <option value =" 0" >Full</option >
215
+ <option value =" 1" >Half</option >
216
+ <option value =" 2" >Almost empty</option >
217
+ </select >
218
+
219
+ But don't be confused! If ``Full `` is selected (value ``0 `` in HTML), ``1 ``
220
+ will be returned in your form. If ``Almost empty `` is selected (value ``2 ``
221
+ in HTML), ``0.1 `` will be returned.
222
+
223
+ choice_loader
224
+ ~~~~~~~~~~~~~
225
+
226
+ .. versionadded :: 2.7
227
+
228
+ The ``choice_loader `` option was added in Symfony 2.7.
229
+
230
+ **type **: :class: `Symfony\\ Component\\ Form\\ ChoiceList\\ Loader\\ ChoiceLoaderInterface `
231
+
232
+ The ``choice_loader `` can be used to only partially load the choices in cases where
233
+ a fully-loaded list is not necessary. This is only needed in advanced cases and
234
+ would replace the ``choices `` option.
235
+
236
+ .. include :: /reference/forms/types/options/choice_name.rst.inc
237
+
238
+ .. include :: /reference/forms/types/options/choice_translation_domain.rst.inc
239
+
240
+ .. include :: /reference/forms/types/options/choice_value.rst.inc
241
+
175
242
choices_as_values
176
243
~~~~~~~~~~~~~~~~~
177
244
@@ -213,83 +280,15 @@ type behaves as if it were set to true:
213
280
'choices' => array('Male' => 'm', 'Female' => 'f'),
214
281
));
215
282
216
- choice_loader
217
- ~~~~~~~~~~~~~
218
-
219
- .. versionadded :: 2.7
220
-
221
- The ``choice_loader `` option was added in Symfony 2.7.
222
-
223
- **type **: :class: `Symfony\\ Component\\ Form\\ ChoiceList\\ Loader\\ ChoiceLoaderInterface `
224
-
225
- The ``choice_loader `` can be used to only partially load the choices in cases where
226
- a fully-loaded list is not necessary. This is only needed in advanced cases and
227
- would replace the ``choices `` option.
228
-
229
- .. _reference-form-choice-label :
230
-
231
- .. include :: /reference/forms/types/options/choice_label.rst.inc
232
-
233
- .. include :: /reference/forms/types/options/choice_attr.rst.inc
234
-
235
- .. include :: /reference/forms/types/options/placeholder.rst.inc
236
-
237
- .. include :: /reference/forms/types/options/choice_translation_domain.rst.inc
238
-
239
283
.. include :: /reference/forms/types/options/expanded.rst.inc
240
284
241
- .. include :: /reference/forms/types/options/multiple.rst.inc
242
-
243
- .. include :: /reference/forms/types/options/preferred_choices.rst.inc
244
-
245
285
.. include :: /reference/forms/types/options/group_by.rst.inc
246
286
247
- .. include :: /reference/forms/types/options/choice_value.rst.inc
248
-
249
- .. include :: /reference/forms/types/options/choice_name.rst.inc
250
-
251
-
252
- choice_list
253
- ~~~~~~~~~~~
254
-
255
- .. caution ::
256
-
257
- The ``choice_list `` option of ChoiceType was deprecated in Symfony 2.7.
258
- You should use `choices `_ or `choice_loader `_ now.
259
-
260
- **type **: :class: `Symfony\\ Component\\ Form\\ Extension\\ Core\\ ChoiceList\\ ChoiceListInterface `
261
-
262
- This is one way of specifying the options to be used for this field.
263
- The ``choice_list `` option must be an instance of the ``ChoiceListInterface ``.
264
- For more advanced cases, a custom class that implements the interface
265
- can be created to supply the choices.
266
-
267
- With this option you can also allow float values to be selected as data.
268
- For example::
269
-
270
- use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
271
-
272
- // ...
273
- $builder->add('status', 'choice', array(
274
- 'choice_list' => new ChoiceList(
275
- array(1, 0.5, 0.1),
276
- array('Full', 'Half', 'Almost empty')
277
- )
278
- ));
279
-
280
- The ``status `` field created by the code above will be rendered as:
281
-
282
- .. code-block :: html
287
+ .. include :: /reference/forms/types/options/multiple.rst.inc
283
288
284
- <select name =" status" >
285
- <option value =" 0" >Full</option >
286
- <option value =" 1" >Half</option >
287
- <option value =" 2" >Almost empty</option >
288
- </select >
289
+ .. include :: /reference/forms/types/options/placeholder.rst.inc
289
290
290
- But don't be confused! If ``Full `` is selected (value ``0 `` in HTML), ``1 ``
291
- will be returned in your form. If ``Almost empty `` is selected (value ``2 ``
292
- in HTML), ``0.1 `` will be returned.
291
+ .. include :: /reference/forms/types/options/preferred_choices.rst.inc
293
292
294
293
Overridden Options
295
294
------------------
0 commit comments