From cea3741d623b4eb092604ee515a06095a5e242bb Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Wed, 17 Sep 2014 14:41:44 +0200 Subject: [PATCH] Added information about float choice lists --- reference/forms/types/choice.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 7f4ab96061f..9b2ef49971c 100644 --- a/reference/forms/types/choice.rst +++ b/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