Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Mar 16, 2021
2 parents d5789c0 + f5d0492 commit a65d8d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Resources/views/Form/bootstrap_4_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,28 @@
{% endblock %}

{% block form_widget_simple -%}
{% if type is not defined or type != 'hidden' %}
{%- set attr = attr|merge({class: (attr.class|default('') ~ (type|default('') == 'file' ? ' custom-file-input' : ' form-control'))|trim}) -%}
{% endif %}
{%- if type is not defined or type != 'hidden' -%}
{%- set className = ' form-control' -%}
{%- if type|default('') == 'file' -%}
{%- set className = ' custom-file-input' -%}
{%- elseif type|default('') == 'range' -%}
{%- set className = ' form-control-range' -%}
{%- endif -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ className)|trim}) -%}
{%- endif -%}
{%- if type is defined and (type == 'range' or type == 'color') %}
{# Attribute "required" is not supported #}
{%- set required = false -%}
{% endif %}
{{- parent() -}}
{%- endblock form_widget_simple %}

{%- block widget_attributes -%}
{%- if not valid %}
{% block widget_attributes -%}
{%- if not valid -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %}
{% endif -%}
{%- endif -%}
{{ parent() }}
{%- endblock widget_attributes -%}
{%- endblock widget_attributes %}

{% block button_widget -%}
{%- set attr = attr|merge({class: (attr.class|default('btn-secondary') ~ ' btn')|trim}) -%}
Expand Down
36 changes: 36 additions & 0 deletions Tests/Extension/AbstractBootstrap4LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\Extension\Core\Type\RangeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormError;

Expand Down Expand Up @@ -1227,6 +1228,41 @@ public function testPercentCustomSymbol()
[contains(.., "‱")]
]
]
'
);
}

public function testRange()
{
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5]]);

$this->assertWidgetMatchesXpath(
$form->createView(),
['attr' => ['class' => 'my&class']],
'/input
[@type="range"]
[@name="name"]
[@value="42"]
[@min="5"]
[@class="my&class form-control-range"]
'
);
}

public function testRangeWithMinMaxValues()
{
$form = $this->factory->createNamed('name', RangeType::class, 42, ['attr' => ['min' => 5, 'max' => 57]]);

$this->assertWidgetMatchesXpath(
$form->createView(),
['attr' => ['class' => 'my&class']],
'/input
[@type="range"]
[@name="name"]
[@value="42"]
[@min="5"]
[@max="57"]
[@class="my&class form-control-range"]
'
);
}
Expand Down

0 comments on commit a65d8d3

Please sign in to comment.