Skip to content

Commit 9e92356

Browse files
authored
Merge pull request #23 from tales-from-a-dev/bugfix/hidden-type
🐛 Do not apply class attribute on hidden type
2 parents da44077 + ac76cdc commit 9e92356

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

phpunit.xml.dist

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
cacheDirectory=".phpunit.cache"
66
executionOrder="depends,defects"
@@ -17,12 +17,15 @@
1717
</testsuites>
1818

1919
<coverage>
20-
<include>
21-
<directory suffix=".php">src</directory>
22-
</include>
2320
<report>
2421
<clover outputFile=".coverage/coverage.xml"/>
2522
<html outputDirectory=".coverage/html/"/>
2623
</report>
2724
</coverage>
25+
26+
<source>
27+
<include>
28+
<directory suffix=".php">src</directory>
29+
</include>
30+
</source>
2831
</phpunit>

templates/form/default.html.twig

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
{%- block form_widget_simple -%}
66
{%- set type = type|default('text') -%}
7-
{%- set attr_class = attr_class|default(block('class_input_text')) -%}
8-
{%- if type == 'range' -%}
9-
{%- set attr_class = block('class_input_range') -%}
10-
{%- elseif type == 'file' -%}
11-
{%- set attr_class = block('class_input_file') -%}
7+
{%- if type == 'hidden' -%}
8+
{{- parent() -}}
9+
{%- else -%}
10+
{%- set attr_class = attr_class|default(block('class_input_text')) -%}
11+
{%- if type == 'range' -%}
12+
{%- set attr_class = block('class_input_range') -%}
13+
{%- elseif type == 'file' -%}
14+
{%- set attr_class = block('class_input_file') -%}
15+
{%- endif -%}
16+
{%- set attr = attr|merge({'class': (attr_class ~ ' ' ~ attr.class|default(''))|trim}) -%}
17+
{{- parent() -}}
1218
{%- endif -%}
13-
{%- set attr = attr|merge({'class': (attr_class ~ ' ' ~ attr.class|default(''))|trim}) -%}
14-
{{- parent() -}}
1519
{%- endblock form_widget_simple -%}
1620

1721
{%- block textarea_widget -%}

tests/FormLayout/BirthdayLayoutTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class BirthdayLayoutTest extends AbstractFlowbiteLayoutTestCase
1111
{
12-
public function testBirthDay(): void
12+
public function testBirthday(): void
1313
{
1414
$form = $this->factory->createNamed('birthday', BirthdayType::class, '2000-02-03', [
1515
'input' => 'string',
@@ -54,7 +54,7 @@ public function testBirthDay(): void
5454
);
5555
}
5656

57-
public function testBirthDaySingleText(): void
57+
public function testBirthdaySingleText(): void
5858
{
5959
$form = $this->factory->createNamed('birthday', BirthdayType::class, '2000-02-03', [
6060
'input' => 'string',

tests/FormLayout/HiddenLayoutTest.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;
6+
7+
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
8+
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;
9+
10+
final class HiddenLayoutTest extends AbstractFlowbiteLayoutTestCase
11+
{
12+
public function testHidden(): void
13+
{
14+
$form = $this->factory->createNamed('name', HiddenType::class);
15+
16+
$this->assertWidgetMatchesXpath($form->createView(), [],
17+
'/input
18+
[@type="hidden"]
19+
[@name="name"]
20+
[@id="name"]'
21+
);
22+
}
23+
24+
public function testHiddenWithClass(): void
25+
{
26+
$form = $this->factory->createNamed('name', HiddenType::class, null, [
27+
'attr' => [
28+
'class' => 'foo bar',
29+
],
30+
]);
31+
32+
$this->assertWidgetMatchesXpath($form->createView(), [],
33+
'/input
34+
[@type="hidden"]
35+
[@name="name"]
36+
[@id="name"]
37+
[@class="foo bar"]'
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)