Skip to content

Commit

Permalink
Merge pull request #23 from tales-from-a-dev/bugfix/hidden-type
Browse files Browse the repository at this point in the history
🐛 Do not apply class attribute on hidden type
  • Loading branch information
ker0x authored Jan 16, 2024
2 parents da44077 + ac76cdc commit 9e92356
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
11 changes: 7 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
Expand All @@ -17,12 +17,15 @@
</testsuites>

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile=".coverage/coverage.xml"/>
<html outputDirectory=".coverage/html/"/>
</report>
</coverage>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
18 changes: 11 additions & 7 deletions templates/form/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

{%- block form_widget_simple -%}
{%- set type = type|default('text') -%}
{%- set attr_class = attr_class|default(block('class_input_text')) -%}
{%- if type == 'range' -%}
{%- set attr_class = block('class_input_range') -%}
{%- elseif type == 'file' -%}
{%- set attr_class = block('class_input_file') -%}
{%- if type == 'hidden' -%}
{{- parent() -}}
{%- else -%}
{%- set attr_class = attr_class|default(block('class_input_text')) -%}
{%- if type == 'range' -%}
{%- set attr_class = block('class_input_range') -%}
{%- elseif type == 'file' -%}
{%- set attr_class = block('class_input_file') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr_class ~ ' ' ~ attr.class|default(''))|trim}) -%}
{{- parent() -}}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr_class ~ ' ' ~ attr.class|default(''))|trim}) -%}
{{- parent() -}}
{%- endblock form_widget_simple -%}

{%- block textarea_widget -%}
Expand Down
4 changes: 2 additions & 2 deletions tests/FormLayout/BirthdayLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class BirthdayLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testBirthDay(): void
public function testBirthday(): void
{
$form = $this->factory->createNamed('birthday', BirthdayType::class, '2000-02-03', [
'input' => 'string',
Expand Down Expand Up @@ -54,7 +54,7 @@ public function testBirthDay(): void
);
}

public function testBirthDaySingleText(): void
public function testBirthdaySingleText(): void
{
$form = $this->factory->createNamed('birthday', BirthdayType::class, '2000-02-03', [
'input' => 'string',
Expand Down
40 changes: 40 additions & 0 deletions tests/FormLayout/HiddenLayoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace TalesFromADev\FlowbiteBundle\Tests\FormLayout;

use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase;

final class HiddenLayoutTest extends AbstractFlowbiteLayoutTestCase
{
public function testHidden(): void
{
$form = $this->factory->createNamed('name', HiddenType::class);

$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
[@type="hidden"]
[@name="name"]
[@id="name"]'
);
}

public function testHiddenWithClass(): void
{
$form = $this->factory->createNamed('name', HiddenType::class, null, [
'attr' => [
'class' => 'foo bar',
],
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
[@type="hidden"]
[@name="name"]
[@id="name"]
[@class="foo bar"]'
);
}
}

0 comments on commit 9e92356

Please sign in to comment.