diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php index 299f919373403..ac900be1066ea 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php @@ -207,7 +207,7 @@ public function onSubmit(FormEvent $event): void foreach ($formReindex as $index => $child) { $form->add($index, $this->type, array_replace([ 'property_path' => '['.$index.']', - ], $this->options)); + ], $this->options, ['data' => $child->getData()])); } $data = array_values($data); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php index a1d1a38402892..1661519b717b1 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php @@ -257,7 +257,7 @@ public function testCollectionTypeKeepAsListOptionTrue() { $formMetadata = new ClassMetadata(Form::class); $authorMetadata = (new ClassMetadata(Author::class)) - ->addPropertyConstraint('firstName', new NotBlank()); + ->addPropertyConstraint('firstName', new Length(1)); $organizationMetadata = (new ClassMetadata(Organization::class)) ->addPropertyConstraint('authors', new Valid()); $metadataFactory = $this->createMock(MetadataFactoryInterface::class); @@ -301,22 +301,22 @@ public function testCollectionTypeKeepAsListOptionTrue() $form->submit([ 'authors' => [ 0 => [ - 'firstName' => '', // Fires a Not Blank Error + 'firstName' => 'foobar', // Fires a Length Error 'lastName' => 'lastName1', ], // key "1" could be missing if we add 4 blank form entries and then remove it. 2 => [ - 'firstName' => '', // Fires a Not Blank Error + 'firstName' => 'barfoo', // Fires a Length Error 'lastName' => 'lastName3', ], 3 => [ - 'firstName' => '', // Fires a Not Blank Error + 'firstName' => 'barbaz', // Fires a Length Error 'lastName' => 'lastName3', ], ], ]); - // Form does have 3 not blank errors + // Form does have 3 length errors $errors = $form->getErrors(true); $this->assertCount(3, $errors); @@ -328,12 +328,15 @@ public function testCollectionTypeKeepAsListOptionTrue() ]; $this->assertTrue($form->get('authors')->has('0')); + $this->assertSame('foobar', $form->get('authors')->get('0')->getData()->firstName); $this->assertContains('data.authors[0].firstName', $errorPaths); $this->assertTrue($form->get('authors')->has('1')); + $this->assertSame('barfoo', $form->get('authors')->get('1')->getData()->firstName); $this->assertContains('data.authors[1].firstName', $errorPaths); $this->assertTrue($form->get('authors')->has('2')); + $this->assertSame('barbaz', $form->get('authors')->get('2')->getData()->firstName); $this->assertContains('data.authors[2].firstName', $errorPaths); $this->assertFalse($form->get('authors')->has('3'));