Skip to content

Conversation

matlad
Copy link

@matlad matlad commented Jan 11, 2019

I Have code

        $directors = $form->addDynamic(
            'directors',
            function (Container $cont) {
               $container->addSelect('id','director', $this->getDirectorList() )
                ...
             },1,true
        );
        ...
        $defaults = []
        foreach ($directors as $director)
        {
             $defaults['directors'][] = ['id' => $director['id']];
        }

        $form->setDefaults($defaults);

Expecting

Form with selects count == count($directors) prefilled or 1 empty if count($directors) == 0

Getting

InvalidArgumentException("Container with name 0 already exists.");

# I Have code
``` php
        $directors = $form->addDynamic(
            'directors',
            function (Container $cont) {
               $container->addSelect('id','director', $this->getDirectorList() )
                ...
             },1,true
        );
        ...
        $defaults = []
        foreach ($directors as $director)
        {
             $defaults['directors'][] = ['id' => $director['id']];
        }

        $form->setDefaults($defaults);
```
# Expecting 
Form with selects count == count($directors) prefilled or 1 empty if count($directors) == 0
# Getting
InvalidArgumentException("Container with name 0 already exists.");
@peldax
Copy link

peldax commented Jun 15, 2019

What was sufficient for me was to remove the $key parameter on like 279 (239 in current release), but this solution works too.

ping @solcik

@solcik
Copy link
Contributor

solcik commented Jun 18, 2019

Sorry, did not get a notification for this till the ping couple days ago.

Tests are failing due to your change.

Please add a test case for your problem. I suppose a problem is with the force parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants