-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] minor fixes in ChoiceType options
- Loading branch information
1 parent
3ba2ad8
commit 4ee4102
Showing
7 changed files
with
51 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
``choice_value`` | ||
~~~~~~~~~~~~~~~~ | ||
|
||
**type**: ``callable`` or ``string`` **default**: ``null`` | ||
**type**: ``callable``, ``string`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: ``null`` | ||
|
||
Returns the string "value" for each choice, which must be unique across all choices. | ||
This is used in the ``value`` attribute in HTML and submitted in the POST/PUT requests. | ||
You don't normally need to worry 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. If ``null`` is given, an incrementing | ||
integer is used as the value. | ||
This can be a callable or a property path. By default, the choices are used if they | ||
can be casted to strings. Otherwise an incrementing integer is used (starting at ``0``). | ||
If you pass a callable, it will receive one argument: the choice itself. When using | ||
the :doc:`/reference/forms/types/entity`, the argument will be the entity object | ||
for each choice or ``null`` in some cases, which you need to handle:: | ||
for each choice or ``null`` in a placeholder is used, which you need to handle:: | ||
'choice_value' => function (MyOptionEntity $entity = null) { | ||
'choice_value' => function (?MyOptionEntity $entity) { | ||
return $entity ? $entity->getId() : ''; | ||
}, | ||
.. caution:: | ||
In Symfony 2.7, there was a small backwards-compatibility break with how the | ||
``value`` attribute of options is generated. This is not a problem unless you | ||
rely on the option values in JavaScript. See `issue #14825`_ for details. | ||
.. _`issue #14825`: https://github.com/symfony/symfony/pull/14825 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters