Skip to content
Browse files

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

  • Loading branch information...
1 parent 11e3516 commit 0a4519d1030e9b3937edd299c84c6cb0ec2bfdad @webmozart webmozart committed Feb 10, 2012
View
9 src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
@@ -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
13 src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig
@@ -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
4 src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_row.html.php
@@ -0,0 +1,4 @@
+<div>
+ <?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
+ <?php echo $view['form']->widget($form) ?>
+</div>
View
8 src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_row.html.php
@@ -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
19 tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php
@@ -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(
View
21 tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php
@@ -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(

0 comments on commit 0a4519d

Please sign in to comment.
Something went wrong with that request. Please try again.