Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Keep submitted values when keep_as_list option of collection type is enabled #59910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.2
Choose a base branch
Loading
from
Open
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 @@ -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);
}
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.