Skip to content

Commit

Permalink
[Form] Removing self-closing slash from <input>
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLandauer authored and fabpot committed Aug 1, 2023
1 parent edf4c22 commit dcb5bb8
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Resources/views/Form/form_div_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{# Attribute "required" is not supported #}
{%- set required = false -%}
{%- endif -%}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
<input type="{{ type }}" {{ block('widget_attributes') }}{% if value is not empty %} value="{{ value }}"{% endif %}>
{%- endblock form_widget_simple -%}

{%- block form_widget_compound -%}
Expand Down Expand Up @@ -91,11 +91,11 @@
{%- endblock choice_widget_options -%}

{%- block checkbox_widget -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
{%- endblock checkbox_widget -%}

{%- block radio_widget -%}
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
{%- endblock radio_widget -%}

{%- block datetime_widget -%}
Expand Down Expand Up @@ -402,7 +402,7 @@
{%- endif -%}
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
<input type="hidden" name="_method" value="{{ method }}">
{%- endif -%}
{%- endblock form_start -%}

Expand Down Expand Up @@ -440,7 +440,7 @@
{%- endif -%}

{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
<input type="hidden" name="_method" value="{{ method }}">
{%- endif -%}
{% endif -%}
{% endblock form_rest %}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Extension/AbstractBootstrap3LayoutTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ public function testWidgetAttributes()
$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value">', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand All @@ -2784,7 +2784,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
$html = $this->renderWidget($form->createView());

// foo="foo"
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value">', $html);
}

public function testButtonAttributes()
Expand Down
7 changes: 5 additions & 2 deletions Tests/Extension/AbstractLayoutTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ protected function assertXpathNodeValue(\DOMElement $element, $expression, $node
protected function assertMatchesXpath($html, $expression, $count = 1)
{
$dom = new \DOMDocument('UTF-8');

$html = preg_replace('/(<input [^>]+)(?<!\/)>/', '$1/>', $html);

try {
// Wrap in <root> node so we can load HTML with multiple tags at
// the top level
Expand Down Expand Up @@ -2511,7 +2514,7 @@ public function testWidgetAttributes()
$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value">', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand All @@ -2523,7 +2526,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
$html = $this->renderWidget($form->createView());

// foo="foo"
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value">', $html);
}

public function testWidgetAttributeHiddenIfFalse()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Extension/Fixtures/templates/form/theme.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
2 changes: 1 addition & 1 deletion Tests/Extension/FormExtensionBootstrap3LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testMoneyWidgetInIso()
$this->assertSame(<<<'HTML'
<div class="input-group">
<span class="input-group-addon">&euro; </span>
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
<input type="text" id="name" name="name" required="required" class="form-control"> </div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Extension/FormExtensionBootstrap4LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testMoneyWidgetInIso()
$this->assertSame(<<<'HTML'
<div class="input-group "><div class="input-group-prepend">
<span class="input-group-text">&euro; </span>
</div><input type="text" id="name" name="name" required="required" class="form-control" /></div>
</div><input type="text" id="name" name="name" required="required" class="form-control"></div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Extension/FormExtensionBootstrap5LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testMoneyWidgetInIso()
->createView();

self::assertSame(<<<'HTML'
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control" /></div>
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control"></div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Extension/FormExtensionDivLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function testMoneyWidgetInIso()
->createView()
;

$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required">', $this->renderWidget($view));
}

public function testHelpAttr()
Expand Down

0 comments on commit dcb5bb8

Please sign in to comment.