Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,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[$index] = $child->getData();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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'));
Expand Down
Loading