Skip to content

Commit a65d8d3

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Console] ProgressBar clears too many lines on update [FrameworkBundle] Exclude unreadable files when executing About command [Bridge\Twig] Add 'form-control-range' for range input type Be explicit about transparent background color of links in toolbar [Translation] fix test case name [Cache] Fix wrong namespace in test [DependencyInjection] Fix return type
2 parents d5789c0 + f5d0492 commit a65d8d3

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,28 @@
134134
{% endblock %}
135135

136136
{% block form_widget_simple -%}
137-
{% if type is not defined or type != 'hidden' %}
138-
{%- set attr = attr|merge({class: (attr.class|default('') ~ (type|default('') == 'file' ? ' custom-file-input' : ' form-control'))|trim}) -%}
139-
{% endif %}
137+
{%- if type is not defined or type != 'hidden' -%}
138+
{%- set className = ' form-control' -%}
139+
{%- if type|default('') == 'file' -%}
140+
{%- set className = ' custom-file-input' -%}
141+
{%- elseif type|default('') == 'range' -%}
142+
{%- set className = ' form-control-range' -%}
143+
{%- endif -%}
144+
{%- set attr = attr|merge({class: (attr.class|default('') ~ className)|trim}) -%}
145+
{%- endif -%}
140146
{%- if type is defined and (type == 'range' or type == 'color') %}
141147
{# Attribute "required" is not supported #}
142148
{%- set required = false -%}
143149
{% endif %}
144150
{{- parent() -}}
145151
{%- endblock form_widget_simple %}
146152

147-
{%- block widget_attributes -%}
148-
{%- if not valid %}
153+
{% block widget_attributes -%}
154+
{%- if not valid -%}
149155
{% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %}
150-
{% endif -%}
156+
{%- endif -%}
151157
{{ parent() }}
152-
{%- endblock widget_attributes -%}
158+
{%- endblock widget_attributes %}
153159

154160
{% block button_widget -%}
155161
{%- set attr = attr|merge({class: (attr.class|default('btn-secondary') ~ ' btn')|trim}) -%}

Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
2020
use Symfony\Component\Form\Extension\Core\Type\PercentType;
2121
use Symfony\Component\Form\Extension\Core\Type\RadioType;
22+
use Symfony\Component\Form\Extension\Core\Type\RangeType;
2223
use Symfony\Component\Form\Extension\Core\Type\TextType;
2324
use Symfony\Component\Form\FormError;
2425

@@ -1227,6 +1228,41 @@ public function testPercentCustomSymbol()
12271228
[contains(.., "‱")]
12281229
]
12291230
]
1231+
'
1232+
);
1233+
}
1234+
1235+
public function testRange()
1236+
{
1237+
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5]]);
1238+
1239+
$this->assertWidgetMatchesXpath(
1240+
$form->createView(),
1241+
['attr' => ['class' => 'my&class']],
1242+
'/input
1243+
[@type="range"]
1244+
[@name="name"]
1245+
[@value="42"]
1246+
[@min="5"]
1247+
[@class="my&class form-control-range"]
1248+
'
1249+
);
1250+
}
1251+
1252+
public function testRangeWithMinMaxValues()
1253+
{
1254+
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5, 'max' => 57]]);
1255+
1256+
$this->assertWidgetMatchesXpath(
1257+
$form->createView(),
1258+
['attr' => ['class' => 'my&class']],
1259+
'/input
1260+
[@type="range"]
1261+
[@name="name"]
1262+
[@value="42"]
1263+
[@min="5"]
1264+
[@max="57"]
1265+
[@class="my&class form-control-range"]
12301266
'
12311267
);
12321268
}

0 commit comments

Comments
 (0)