Explorar o código

[Form] fixed error bubbling for Date and Time types when rendering as multiple choices (closes #2062)

Fabien Potencier %!s(int64=13) %!d(string=hai) anos
pai
achega
73c8d2ba74

+ 11 - 10
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -157,18 +157,19 @@ class DateType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'years'         => range(date('Y') - 5, date('Y') + 5),
-            'months'        => range(1, 12),
-            'days'          => range(1, 31),
-            'widget'        => 'choice',
-            'input'         => 'datetime',
-            'format'        => \IntlDateFormatter::MEDIUM,
-            'data_timezone' => null,
-            'user_timezone' => null,
-            'empty_value'   => null,
+            'years'          => range(date('Y') - 5, date('Y') + 5),
+            'months'         => range(1, 12),
+            'days'           => range(1, 31),
+            'widget'         => 'choice',
+            'input'          => 'datetime',
+            'format'         => \IntlDateFormatter::MEDIUM,
+            'data_timezone'  => null,
+            'user_timezone'  => null,
+            'empty_value'    => null,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
-            'by_reference'  => false,
+            'by_reference'   => false,
+            'error_bubbling' => false,
         );
     }
 

+ 11 - 10
src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

@@ -123,18 +123,19 @@ class TimeType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'hours'         => range(0, 23),
-            'minutes'       => range(0, 59),
-            'seconds'       => range(0, 59),
-            'widget'        => 'choice',
-            'input'         => 'datetime',
-            'with_seconds'  => false,
-            'data_timezone' => null,
-            'user_timezone' => null,
-            'empty_value'   => null,
+            'hours'          => range(0, 23),
+            'minutes'        => range(0, 59),
+            'seconds'        => range(0, 59),
+            'widget'         => 'choice',
+            'input'          => 'datetime',
+            'with_seconds'   => false,
+            'data_timezone'  => null,
+            'user_timezone'  => null,
+            'empty_value'    => null,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
-            'by_reference'  => false,
+            'by_reference'   => false,
+            'error_bubbling' => false,
         );
     }
 

+ 22 - 0
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -1120,6 +1120,17 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testDateErrorBubbling()
+    {
+        $child = $this->factory->createNamed('date', 'date');
+        $form = $this->factory->createNamed('form', 'form')->add($child);
+        $child->addError(new FormError('Error!'));
+        $view = $form->createView();
+
+        $this->assertEmpty($this->renderErrors($view));
+        $this->assertNotEmpty($this->renderErrors($view['date']));
+    }
+
     public function testBirthDay()
     {
         $form = $this->factory->createNamed('birthday', 'na&me', '2000-02-03', array(
@@ -1646,6 +1657,17 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testTimeErrorBubbling()
+    {
+        $child = $this->factory->createNamed('time', 'time');
+        $form = $this->factory->createNamed('form', 'form')->add($child);
+        $child->addError(new FormError('Error!'));
+        $view = $form->createView();
+
+        $this->assertEmpty($this->renderErrors($view));
+        $this->assertNotEmpty($this->renderErrors($view['time']));
+    }
+
     public function testTimezone()
     {
         $form = $this->factory->createNamed('timezone', 'na&me', 'Europe/Vienna', array(