Skip to content

clarify the signature of the choice_value callable #6297

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 3 commits into from

Conversation

backbone87
Copy link
Contributor

Q A
Doc fix? yes
New docs? no
Applies to 2.7+
Fixed tickets

@@ -12,7 +12,10 @@ about this, but it might be handy when processing an API request (since you can
configure the value that will be sent in the API request).

This can be a callable or a property path. See `choice_label`_ for similar usage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to remove "See choice_label_ for similar usage. completely. This would avoid talking about "differences" with the other options.

@HeahDude
Copy link
Contributor

👍 to be more explicit with this option.
Also, I've read in an issue that someone was missing the fact that it's an entity which is passed in EntityType. It would be nice to explicit the fact that it's the choice model data that is passed.
And a caution as this callable is also called with the default data which is often null or an empty string so it throws an exception if you used method on object choices.
Finally I would suggest to say something about the responsibility to return a unique string representation.

@backbone87
Copy link
Contributor Author

@HeahDude i agree with you on everything, but i think its out of scope for this PR, since it is just a quick doc fix, to avoid errors

#6144 requests a general overhaul / clarification of the choice type / choice list components

@HeahDude
Copy link
Contributor

Alright then ;) But at least, to quickly avoid errors, I hardly recommend to remove that line as I said in inline comment.

*If you use a callable for this option, it gets passed the choice as its **only**
argument*. This is a difference compared to the callables of `choice_label`_ and
`choice_name`_, which receive additional arguments. If ``null`` is used, an
incrementing integer is used as the name.
Copy link
Member

Choose a reason for hiding this comment

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

I agree that it would be best to have the section overhauled in general, but I also agree that this is a nice short-term fix. However, I suggest to change this a bit to something like this:

.. note::

    In contrast to the ``choice_label`` and ``choice_name`` option when using
    a callable for the ``choice_value`` option, the actual choice is the **only**
    argument passed to it.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

This is a detail but I would say :

.. note::

    In contrast to other choice options (e.g ``choice_label``), the callable for
    the ``choice_value`` option takes as **only** argument the actual choice.

Because the actual enumeration misses choice_attr (and maybe future other(s) ;).

Anyway please remove See choice_label_ for similar usage., as I really think it can confuse new comers.

@backbone87
Copy link
Contributor Author

i have applied your feedback, can be autosquashed for clean history


In contrast to other choice options (e.g. `choice_label`_), the callable for
the ``choice_value`` option takes as **only** argument the actual choice, which
is also the value that gets passed to your model after submitting the form.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would replace after by when.

Beside that 👍

@backbone87
Copy link
Contributor Author

done


In contrast to other choice options (e.g. `choice_label`_), the callable for
the ``choice_value`` option takes as **only** argument the actual choice, which
is also the value that gets passed to your model when submitting the form.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but now I'm re-reading it and I think that ", which is also the value that gets passed to your model when submitting the form" is too confusing. It better should be defined outside of this note, when clarifying the responsibility of this option to return a unique string representation of the choice.

Copy link
Member

Choose a reason for hiding this comment

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

@backbone87 Can you reword this a bit?

weaverryan added a commit that referenced this pull request Sep 27, 2017
…one87)

This PR was squashed before being merged into the 2.7 branch (closes #6297).

Discussion
----------

clarify the signature of the choice_value callable

| Q | A |
| --- | --- |
| Doc fix? | yes |
| New docs? | no |
| Applies to | 2.7+ |
| Fixed tickets |  |

Commits
-------

5cf83f6 clarify the signature of the choice_value callable
weaverryan added a commit that referenced this pull request Sep 27, 2017
@weaverryan
Copy link
Member

Thanks! I've just merged this, and tried to clarify further at sha: 6365c01

@weaverryan weaverryan closed this Sep 27, 2017
fabpot added a commit to symfony/symfony that referenced this pull request Mar 17, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

[Form] Fixed some phpdocs

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | symfony/symfony-docs#6393

ref symfony/symfony-docs#6144, symfony/symfony-docs#6297, #14050

Commits
-------

b9162e8 [Form] Fixed some phpdocs
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