merged branch bschussek/issue2308 (PR #3320)

Commits
-------

0a4519d [Form] Fixed duplicate errors on forms with "error_bubbling"=false

Discussion
----------

[Form] Fixed duplicate errors on forms with "error_bubbling"=false

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #2308
Todo: -

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue2308)
This commit is contained in:
Fabien Potencier 2012-02-10 12:59:38 +01:00
commit c614be74c8
6 changed files with 74 additions and 0 deletions

View File

@ -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 %}

View File

@ -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 %}

View File

@ -0,0 +1,4 @@
<div>
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
<?php echo $view['form']->widget($form) ?>
</div>

View File

@ -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>

View File

@ -344,6 +344,25 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
);
}
// 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(

View File

@ -196,6 +196,27 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
);
}
// 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(