Skip to content

Commit f4e4730

Browse files
author
Elnur Abdurrakhimov
committed
Added a section on the empty_data option of the choice form type.
1 parent 155deba commit f4e4730

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

reference/forms/types/choice.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ option.
1919
| | - `expanded`_ |
2020
| | - `preferred_choices`_ |
2121
| | - `empty_value`_ |
22+
| | - `empty_data`_ |
2223
+-------------+-----------------------------------------------------------------------------+
2324
| Inherited | - `required`_ |
2425
| options | - `label`_ |
@@ -101,6 +102,8 @@ can be created to supply the choices.
101102

102103
.. include:: /reference/forms/types/options/empty_value.rst.inc
103104

105+
.. include:: /reference/forms/types/options/empty_data.rst.inc
106+
104107
Inherited options
105108
-----------------
106109

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
empty_data
2+
~~~~~~~~~~
3+
4+
**type**: ``mixed`` **default**: ``array()`` if ``multiple`` or ``expanded``, ``''`` otherwise
5+
6+
This option determines what value the field will return when the ``empty_value``
7+
choice is selected.
8+
9+
For example, if you want the ``gender`` field to be set to ``null`` when no
10+
value is selected, you can do it like this:
11+
12+
.. code-block:: php
13+
14+
$builder->add('gender', 'choice', array(
15+
'choices' => array(
16+
'm' => 'Male',
17+
'f' => 'Female'
18+
),
19+
'required' => false,
20+
'empty_value' => 'Choose your gender',
21+
'empty_data' => null
22+
));

0 commit comments

Comments
 (0)