File tree 3 files changed +30
-1
lines changed
Filter options
3 files changed +30
-1
lines changed
Original file line number Diff line number Diff line change 65
65
{%- endif -%}
66
66
{%- if preferred_choices | length > 0 -%}
67
67
{% set options = preferred_choices %}
68
+ {% set render_preferred_choices = true %}
68
69
{{- block (' choice_widget_options' ) -}}
69
70
{%- if choices | length > 0 and separator is not none -%}
70
71
<option disabled =" disabled" >{{ separator }}</option >
71
72
{%- endif -%}
72
73
{%- endif -%}
73
74
{%- set options = choices -%}
75
+ {%- set render_preferred_choices = false -%}
74
76
{{- block (' choice_widget_options' ) -}}
75
77
</select >
76
78
{%- endblock choice_widget_collapsed -%}
83
85
{{- block (' choice_widget_options' ) -}}
84
86
</optgroup >
85
87
{%- else -%}
86
- <option value =" {{ choice .value }}" {% if choice .attr %}{% with { attr : choice .attr } %}{{ block (' attributes' ) }}{% endwith %}{% endif %}{% if choice is selectedchoice(value ) %} selected =" selected" {% endif %}>{{ choice_translation_domain is same as (false ) ? choice .label : choice .label | trans({}, choice_translation_domain ) }}</option >
88
+ <option value =" {{ choice .value }}" {% if choice .attr %}{% with { attr : choice .attr } %}{{ block (' attributes' ) }}{% endwith %}{% endif %}{% if not render_preferred_choices | default ( false ) and choice is selectedchoice(value ) %} selected =" selected" {% endif %}>{{ choice_translation_domain is same as (false ) ? choice .label : choice .label | trans({}, choice_translation_domain ) }}</option >
87
89
{%- endif -%}
88
90
{% endfor %}
89
91
{%- endblock choice_widget_options -%}
Original file line number Diff line number Diff line change 160
160
{%- endif %}
161
161
{%- if preferred_choices | length > 0 -%}
162
162
{% set options = preferred_choices %}
163
+ {% set render_preferred_choices = true %}
163
164
{{- block (' choice_widget_options' ) -}}
164
165
{% if choices | length > 0 and separator is not none -%}
165
166
<option disabled =" disabled" >{{ separator }}</option >
166
167
{%- endif %}
167
168
{%- endif -%}
168
169
{% set options = choices -%}
170
+ {%- set render_preferred_choices = false -%}
169
171
{{- block (' choice_widget_options' ) -}}
170
172
</select >
171
173
{%- endblock choice_widget_collapsed %}
Original file line number Diff line number Diff line change @@ -531,6 +531,31 @@ public function testSingleChoiceWithPreferred()
531
531
);
532
532
}
533
533
534
+ public function testSingleChoiceWithSelectedPreferred ()
535
+ {
536
+ $ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , [
537
+ 'choices ' => ['Choice&A ' => '&a ' , 'Choice&B ' => '&b ' ],
538
+ 'preferred_choices ' => ['&a ' ],
539
+ 'multiple ' => false ,
540
+ 'expanded ' => false ,
541
+ ]);
542
+
543
+ $ this ->assertWidgetMatchesXpath ($ form ->createView (), ['separator ' => '-- sep -- ' , 'attr ' => ['class ' => 'my&class ' ]],
544
+ '/select
545
+ [@name="name"]
546
+ [@class="my&class form-control"]
547
+ [not(@required)]
548
+ [
549
+ ./option[@value="&a"][not(@selected)][.="[trans]Choice&A[/trans]"]
550
+ /following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
551
+ /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
552
+ /following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
553
+ ]
554
+ [count(./option)=4]
555
+ '
556
+ );
557
+ }
558
+
534
559
public function testSingleChoiceWithPreferredAndNoSeparator ()
535
560
{
536
561
$ form = $ this ->factory ->createNamed ('name ' , 'Symfony\Component\Form\Extension\Core\Type\ChoiceType ' , '&a ' , [
You can’t perform that action at this time.
0 commit comments