Kdyby / FormsReplicator

Other
30 stars 57 forks source link

default values and createdefault error #55

Open matlad opened 5 years ago

matlad commented 5 years ago

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.");

peldax commented 5 years ago

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 commented 5 years ago

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.