Skip to content

Commit

Permalink
[Form] Fixed duplicate errors on forms with "error_bubbling"=false
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Feb 10, 2012
1 parent 11e3516 commit 0a4519d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
Expand Up @@ -233,6 +233,15 @@
{% endspaceless %}
{% endblock field_row %}

{% block form_row %}
{% spaceless %}
<div>
{{ form_label(form, label|default(null)) }}
{{ form_widget(form) }}
</div>
{% endspaceless %}
{% endblock form_row %}

{% block hidden_row %}
{{ form_widget(form) }}
{% endblock hidden_row %}
Expand Down
Expand Up @@ -14,6 +14,19 @@
{% endspaceless %}
{% endblock field_row %}

{% block form_row %}
{% spaceless %}
<tr>
<td>
{{ form_label(form, label|default(null)) }}
</td>
<td>
{{ form_widget(form) }}
</td>
</tr>
{% endspaceless %}
{% endblock form_row %}

{% block form_errors %}
{% spaceless %}
{% if errors|length > 0 %}
Expand Down
@@ -0,0 +1,4 @@
<div>
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
<?php echo $view['form']->widget($form) ?>
</div>
@@ -0,0 +1,8 @@
<tr>
<td>
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
</td>
<td>
<?php echo $view['form']->widget($form) ?>
</td>
</tr>
19 changes: 19 additions & 0 deletions tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php
Expand Up @@ -344,6 +344,25 @@ public function testForm()
);
}

// https://github.com/symfony/symfony/issues/2308
public function testNestedFormError()
{
$form = $this->factory->createNamedBuilder('form', 'name')
->add('child', 'form', array('error_bubbling' => false))
->getForm();

$form->get('child')->addError(new FormError('Error!'));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/div
[
./div/div[@id="name_child"][./ul/li[.="[trans]Error![/trans]"]]
]
[count(.//li[.="[trans]Error![/trans]"])=1]
'
);
}

public function testRepeated()
{
$form = $this->factory->createNamed('repeated', 'name', 'foobar', array(
Expand Down
21 changes: 21 additions & 0 deletions tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php
Expand Up @@ -196,6 +196,27 @@ public function testForm()
);
}

// https://github.com/symfony/symfony/issues/2308
public function testNestedFormError()
{
$form = $this->factory->createNamedBuilder('form', 'name')
->add('child', 'form', array('error_bubbling' => false))
->getForm();

$form->get('child')->addError(new FormError('Error!'));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/table
[
./tr/td/table
[@id="name_child"]
[./tr/td/ul/li[.="[trans]Error![/trans]"]]
]
[count(.//li[.="[trans]Error![/trans]"])=1]
'
);
}

public function testRepeated()
{
$form = $this->factory->createNamed('repeated', 'name', 'foobar', array(
Expand Down

0 comments on commit 0a4519d

Please sign in to comment.