-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] Added information about float choice lists #4241
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
Conversation
note that this is also useful to choose boolean values, or |
With this option you can also allow float values to be selected as data.:: | ||
|
||
$builder->add('status', 'choice', array( | ||
'choice_list' => new ChoiceList(array(1, 0.5), array('Full', 'Half') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add the use statement
Thank you for the information, just updated accordingly and squashed the commits. |
(e.g. a float or a boolean) you should us the ``choice_list`` option instead. | ||
With this you can keep the original data format. This is also important to ensure | ||
proper validation and to avoid useless Database updates potentially caused by a | ||
wrong data type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rephrase this a bit (and also link to the choice_list
option):
.. 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.
I'm not sure if the part about database updates is that important. What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the doctrine update should be mentionned. It is not even the main issue. There is worse than the noop update: in case of edition, the wrong value will be initially selected when using the wrong type, because Symfony uses strict comparison to choose the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I am unsure about this. However as a side effect you have those updates which might cause updated timestamps, called listeners just based on an altered value. I have added it again to raise awareness, however I am fine with removing it. You guys can decide.
This is a nice note - I've merged it into the 2.3 branch. Thanks Peter! |
Added an information about the possibility to have a choice list with float values.
Relates to symfony/symfony#11849