Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Add option separator to ChoiceType to use a custom separator after preferred choices #52447

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

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
{% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{%- if choices|length > 0 and separator is not none -%}
<option disabled="disabled">{{ separator }}</option>
{%- if separator_html is not defined or separator_html is same as(false) -%}
<option disabled="disabled">{{ separator }}</option>
{% else %}
{{ separator|raw }}
{% endif %}
{%- endif -%}
{%- endif -%}
{%- set options = choices -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@
{% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{% if choices|length > 0 and separator is not none -%}
<option disabled="disabled">{{ separator }}</option>
{%- if separator_html is not defined or separator_html is same as(false) -%}
<option disabled="disabled">{{ separator }}</option>
{% else %}
{{ separator|raw }}
{% endif %}
{%- endif %}
{%- endif -%}
{% set options = choices -%}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.1
---

* Add option `separator` to `ChoiceType` to use a custom separator after preferred choices (use the new `separator_html` option to display the separator text as HTML)
* Deprecate not configuring the `default_protocol` option of the `UrlType`, it will default to `null` in 8.0

7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public function buildView(FormView $view, FormInterface $form, array $options):
'expanded' => $options['expanded'],
'preferred_choices' => $choiceListView->preferredChoices,
'choices' => $choiceListView->choices,
'separator' => '-------------------',
'separator' => $options['separator'],
'separator_html' => $options['separator_html'],
'placeholder' => null,
'placeholder_attr' => [],
'choice_translation_domain' => $choiceTranslationDomain,
Expand Down Expand Up @@ -342,6 +343,8 @@ public function configureOptions(OptionsResolver $resolver): void
'choice_attr' => null,
'choice_translation_parameters' => [],
'preferred_choices' => [],
'separator' => '-------------------',
'separator_html' => false,
'duplicate_preferred_choices' => true,
'group_by' => null,
'empty_data' => $emptyData,
Expand Down Expand Up @@ -372,6 +375,8 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('choice_translation_parameters', ['null', 'array', 'callable', ChoiceTranslationParameters::class]);
$resolver->setAllowedTypes('placeholder_attr', ['array']);
$resolver->setAllowedTypes('preferred_choices', ['array', \Traversable::class, 'callable', 'string', PropertyPath::class, PreferredChoice::class]);
$resolver->setAllowedTypes('separator', ['string']);
$resolver->setAllowedTypes('separator_html', ['bool']);
$resolver->setAllowedTypes('duplicate_preferred_choices', 'bool');
$resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', PropertyPath::class, GroupBy::class]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"multiple",
"placeholder",
"placeholder_attr",
"preferred_choices"
"preferred_choices",
"separator",
"separator_html"
],
"overridden": {
"Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
placeholder getter
placeholder_attr help
preferred_choices help_attr
help_html
help_translation_parameters
separator help_html
separator_html help_translation_parameters
inherit_data
invalid_message_parameters
is_empty_callback
Expand Down