Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2342a7

Browse files
committed
feature#4241 [Form] Added information about float choice lists (peterrehm)
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 tosymfony/symfony#11849Commits-------81e3728 Added information about float choice lists
2 parentsdf16779 +81e3728 commitc2342a7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎reference/forms/types/choice.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ is the item value and the array value is the item's label::
9393
'choices' => array('m' => 'Male', 'f' => 'Female')
9494
));
9595

96+
..tip::
97+
98+
When the values to choose from are not integers or strings (but e.g. floats
99+
or booleans), you should use the `choice_list`_ option instead. With this
100+
option you are able to keep the original data format which is important
101+
to ensure that the user input is validated properly and useless database
102+
updates caused by a data type mismatch are avoided.
103+
96104
choice_list
97105
~~~~~~~~~~~
98106

@@ -103,6 +111,17 @@ The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
103111
For more advanced cases, a custom class that implements the interface
104112
can be created to supply the choices.
105113

114+
With this option you can also allow float values to be selected as data.
115+
116+
..code-block::php
117+
118+
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
119+
120+
// ...
121+
$builder->add('status', 'choice', array(
122+
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half')
123+
));
124+
106125
..include::/reference/forms/types/options/empty_value.rst.inc
107126

108127
..include::/reference/forms/types/options/expanded.rst.inc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp