Skip to content

Added a section on the empty_data option of the choice form type #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option.
| | - `expanded`_ |
| | - `preferred_choices`_ |
| | - `empty_value`_ |
| | - `empty_data`_ |
+-------------+-----------------------------------------------------------------------------+
| Inherited | - `required`_ |
| options | - `label`_ |
Expand Down Expand Up @@ -101,6 +102,8 @@ can be created to supply the choices.

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

.. include:: /reference/forms/types/options/empty_data.rst.inc

Inherited options
-----------------

Expand Down
22 changes: 22 additions & 0 deletions reference/forms/types/options/empty_data.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
empty_data
~~~~~~~~~~

**type**: ``mixed`` **default**: ``array()`` if ``multiple`` or ``expanded``, ``''`` otherwise

This option determines what value the field will return when the ``empty_value``
choice is selected.

For example, if you want the ``gender`` field to be set to ``null`` when no
value is selected, you can do it like this:

.. code-block:: php

$builder->add('gender', 'choice', array(
'choices' => array(
'm' => 'Male',
'f' => 'Female'
),
'required' => false,
'empty_value' => 'Choose your gender',
'empty_data' => null
));