Skip to content

[TwigBridge] Fix Bootstrap 4 form error layout #52373

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

Open
wants to merge 4 commits into
base: 5.4
Choose a base branch
from
Open
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 @@ -257,7 +257,8 @@
{{- label|trans(label_translation_parameters, translation_domain)|raw -}}
{%- endif -%}
{%- endif -%}
{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
</{{ element|default('label') }}>
{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}
{%- else -%}
{%- if errors|length > 0 -%}
<div id="{{ id }}_errors" class="mb-2">
Expand Down Expand Up @@ -315,8 +316,8 @@
{%- endif -%}
{%- endif -%}
{%- endif -%}
{{- form_errors(form) -}}
</label>
{{- form_errors(form) -}}
{%- endif -%}
{%- endblock checkbox_radio_label %}

Expand All @@ -341,7 +342,7 @@

{% block form_errors -%}
{%- if errors|length > 0 -%}
<span class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %} d-block">
<span class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %} d-block mb-1">
{%- for error in errors -%}
<span class="d-block">
<span class="form-error-icon badge badge-danger text-uppercase">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public function testRow()
'/div
[
./label[@for="name"]
[
./span[@class="alert alert-danger d-block"]
[./span[@class="d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
/following-sibling::span[@class="alert alert-danger d-block mb-1"]
[./span[@class="d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
/following-sibling::div[./input[@id="name"]]
]
'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ public function testRow()
'/div
[
./label[@for="name"]
[
./span[@class="alert alert-danger d-block"]
[./span[@class="d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
/following-sibling::span[@class="alert alert-danger d-block mb-1"]
[./span[@class="d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
/following-sibling::input[@id="name"]
]
'
Expand Down Expand Up @@ -324,7 +322,7 @@ public function testErrors()

$this->assertMatchesXpath($html,
'/span
[@class="alert alert-danger d-block"]
[@class="alert alert-danger d-block mb-1"]
[
./span[@class="d-block"]
[./span[.="[trans]Error[/trans]"]]
Expand Down
17 changes: 13 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,18 @@ public function testCompile()
$this->registerTwigRuntimeLoader($environment, $formRenderer);
$compiler = new Compiler($environment);

// There's a different result when testing in Symfony 4 with PHP 8.2 + high-deps
// This workaround is used to deal with the difference.
$source = '[1 => "tpl1", 0 => "tpl2"]';
if ('["tpl1", "tpl2"]' === (new Compiler($environment))->subcompile($node->getNode('resources'))->getSource()) {
$source = '["tpl1", "tpl2"]';
}

$this->assertEquals(
sprintf(
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [1 => "tpl1", 0 => "tpl2"], true);',
$this->getVariableGetter('form')
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, %s, true);',
$this->getVariableGetter('form'),
$source
),
trim($compiler->compile($node)->getSource())
);
Expand All @@ -72,8 +80,9 @@ public function testCompile()

$this->assertEquals(
sprintf(
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, [1 => "tpl1", 0 => "tpl2"], false);',
$this->getVariableGetter('form')
'$this->env->getRuntime("Symfony\\\\Component\\\\Form\\\\FormRenderer")->setTheme(%s, %s, false);',
$this->getVariableGetter('form'),
$source
),
trim($compiler->compile($node)->getSource())
);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy