8000 [Form] Added information about float choice lists by peterrehm · Pull Request #4241 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
8000

[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

Closed
wants to merge 1 commit into from
Closed

[Form] Added information about float choice lists #4241

wants to merge 1 commit into from

Conversation

peterrehm
Copy link
Contributor
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

@peterrehm peterrehm changed the title Added information about float choice lists [Form] Added information about float choice lists Sep 17, 2014
@stof
Copy link
Member
stof commented Sep 17, 2014

note that this is also useful to choose boolean values, or null (anything other than strings and integers actually, as they cannot be array keys)

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')
Copy link
Member

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

@peterrehm
Copy link
Contributor Author

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.
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8000

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.

@weaverryan
Copy link
Member

This is a nice note - I've merged it into the 2.3 branch. Thanks Peter!

@weaverryan weaverryan closed this in c2342a7 Oct 2, 2014
@peterrehm peterrehm deleted the patch-1 branch October 20, 2014 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0