Skip to content

Improved description of choice_list option #5428

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 2 commits into from
Jun 23, 2015
Merged
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
18 changes: 16 additions & 2 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,31 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
For more advanced cases, a custom class that implements the interface
can be created to supply the choices.

With this option you can also allow float values to be selected as data.
With this option you can also allow float values to be selected as data. For example:

.. code-block:: php

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;

// ...
$builder->add('status', 'choice', array(
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half'))
'choice_list' => new ChoiceList(array(1, 0.5, 0.1), array('Full', 'Half', 'Almost empty'))
));

The ``status`` field created by the code above will be rendered as:

.. code-block:: html

<select name="status">
<option value="0">Full</option>
<option value="1">Half</option>
<option value="2">Almost empty</option>
</select>

But don't be confused! If ``Full`` is selected (value ``0`` in HTML), ``1`` will
be returned in your form. If ``Almost empty`` is selected (value ``2`` in HTML),
``0.1`` will be returned.

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

.. include:: /reference/forms/types/options/expanded.rst.inc
Expand Down