Permalink
Browse files

feature #4241 [Form] Added information about float choice lists (pete…

…rrehm)

This PR was submitted for the 2.5 branch but it was merged into the 2.3 branch instead (closes #4241).

Discussion
----------

[Form] Added information about float choice lists

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | no
| Applies to    | all
| Fixed tickets | -

Added an information about the possibility to have a choice list with float values.

Relates to symfony/symfony#11849

Commits
-------

81e3728 Added information about float choice lists
  • Loading branch information...
weaverryan committed Oct 2, 2014
2 parents df16779 + 81e3728 commit c2342a72d0bc237c951b035a02651a1a3ac84c90
Showing with 19 additions and 0 deletions.
  1. +19 −0 reference/forms/types/choice.rst
@@ -93,6 +93,14 @@ is the item value and the array value is the item's label::
'choices' => array('m' => 'Male', 'f' => 'Female')
));
.. tip::
When the values to choose from are not integers or strings (but e.g. floats
or booleans), you should use the `choice_list`_ option instead. With this
option you are able to keep the original data format which is important
to ensure that the user input is validated properly and useless database
updates caused by a data type mismatch are avoided.
choice_list
~~~~~~~~~~~
@@ -103,6 +111,17 @@ 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.
.. 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')
));
.. include:: /reference/forms/types/options/empty_value.rst.inc
.. include:: /reference/forms/types/options/expanded.rst.inc

0 comments on commit c2342a7

Please sign in to comment.