contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework
https://contributte.org/packages/contributte/forms-multiplier.html
MIT License
26 stars 21 forks source link

Method applyDefaultValues can't set default values #11

Closed hrasekj closed 6 years ago

hrasekj commented 7 years ago

Method applyDefaultValues can't set default values becouse method Nette\Forms\Form::isSubmitted() returns true, when dealing with POST request.

The solution would be dummy Form instance. This worked for me.

class FakeForm extends Nette\Forms\Form
{
    public function getHttpData($type = null, $htmlName = null)
    {
    }
}

class Multiplier extends Container
{
    ... code

    protected function applyDefaultValues(Container $container)
    {
        $factoryContainer = (new FakeForm())->addContainer('void');
        $this->fillContainer($factoryContainer);

        foreach ($factoryContainer->getControls() as $name => $control) {
            /** @var IControl $component */
            $component = $container->getComponent($name, false);
            if ($component) {
                $component->setValue($control->getValue());
            }
        }
    }

    ... code
}
MartkCz commented 7 years ago

Which version are you using?