-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[WIP] Update form choice type reference (refs #5179) #5847
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
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f46f134
Added basic choice type changes
althaus 5f6ba80
Added choice_loader basics
althaus 54830f0
Added choices_as_values description
althaus 9a23cd2
Added choices_as_values description [amend]
althaus 01bd200
Fixed linebreaking
althaus 31134f5
Fixed preferred choices example
althaus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
choice_attr | ||
~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.7 | ||
The ``choice_attr`` option was introduced in Symfony 2.7. | ||
|
||
**type**: ``array``, ``callable`` or ``string`` **default**: ``array()`` | ||
|
||
Returns the additional HTML attributes for choices. Can be an array, a callable | ||
(like for ``choice_label``) or a property path. | ||
|
||
If an array, the keys of the ``choices`` array must be used as keys:: | ||
|
||
$builder->add('attending', 'choice', array( | ||
'choices' => array( | ||
'Yes' => true, | ||
'No' => false, | ||
'Maybe' => null, | ||
), | ||
'choices_as_values' => true, | ||
'choice_attr' => array( | ||
'Maybe' => array('class' => 'greyed-out'), | ||
), | ||
)); |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
choice_label | ||
~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.7 | ||
The ``choice_label`` option was introduced in Symfony 2.7. | ||
|
||
**type**: ``callable`` or ``string`` **default**: ``null`` | ||
|
||
Returns the label for each choice. Can be a callable (which receives the choice | ||
as first and the key of the ``choices`` array as second argument) or a property | ||
path. | ||
|
||
If ``null``, the keys of the ``choices`` array are used as labels. | ||
|
||
* Using a callable to set the label:: | ||
|
||
$builder->add('attending', 'choice', array( | ||
'choices' => array( | ||
'yes' => true, | ||
'no' => false, | ||
'maybe' => null, | ||
), | ||
'choices_as_values' => true, | ||
'choice_label' => function ($choice, $key) { | ||
return 'form.choice.'.$key; | ||
}, | ||
)); | ||
|
||
* Using a property path to set the label:: | ||
|
||
$builder->add('attending', 'choice', array( | ||
'choices' => array( | ||
Status::getInstance(Status::YES), | ||
Status::getInstance(Status::NO), | ||
Status::getInstance(Status::MAYBE), | ||
), | ||
'choices_as_values' => true, | ||
'choice_label' => 'displayName', | ||
)); |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
choice_name | ||
~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.7 | ||
The ``choice_name`` option was introduced in Symfony 2.7. | ||
|
||
**type**: ``callable`` or ``string`` **default**: ``null`` | ||
|
||
Returns the form name for each choice. That name is used as name of the | ||
checkbox/radio form for this choice. It is also used as index of the choice | ||
views in the template. Can be a callable (like for ``choice_label``) or a | ||
property path. | ||
|
||
The generated names must be valid form names, i.e. contain alpha-numeric | ||
symbols, underscores, hyphens and colons only. They must start with an | ||
alpha-numeric symbol or an underscore. | ||
|
||
If ``null``, an incrementing integer is used as name. |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
choice_value | ||
~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.7 | ||
The ``choice_value`` option was introduced in Symfony 2.7. | ||
|
||
**type**: ``callable`` or ``string`` **default**: ``null`` | ||
|
||
Returns the string value for each choice. This value is displayed in the | ||
``value`` attributes and submitted in the POST/PUT requests. Can be a | ||
callable (like for ``choice_label``) or a property path. | ||
|
||
If ``null``, an incrementing integer is used as value. |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
group_by | ||
~~~~~~~~ | ||
|
||
.. versionadded:: 2.7 | ||
The ``group_by`` option was introduced in Symfony 2.7. | ||
|
||
**type**: ``array``, ``callable`` or ``string`` **default**: ``null`` | ||
|
||
Returns the grouping used for the choices. Can be an array/Traversable, a | ||
callable (like for ``choice_label``) or a property path. | ||
|
||
The return values of the callable/property path are used as group labels. If | ||
``null`` is returned, a choice is not grouped. | ||
|
||
If ``null``, the structure of the ``choices`` array is used to construct the | ||
groups:: | ||
|
||
$builder->add('attending', 'choice', array( | ||
'choices' => array( | ||
'Decided' => array( | ||
'Yes' => true, | ||
'No' => false, | ||
), | ||
'Undecided' => array( | ||
'Maybe' => null, | ||
), | ||
), | ||
'choices_as_values' => true, | ||
)); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The lines or this paragraph are a bit too long.
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.
@javiereguiluz What's the official line length? Seems I'm blind as I cannot find anything in the contribution guide. :(
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.
We usually break lines after the first word that crosses the 72nd character: http://symfony.com/doc/current/contributing/documentation/standards.html#sphinx
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.
@xabbuh Thanks. Just pushed an update to fix this.