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

This commit is contained in:
Bernhard Schussek 2012-02-10 11:41:19 +01:00
parent 11e3516583
commit 0a4519d103
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(