contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework

Home Page:https://contributte.org/packages/contributte/forms-multiplier.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SetDefaults with UI/Form

kravcik opened this issue · comments

I dont want be annoying. This doesnt create "defaults" containers.

public function actionDefault()
    {
        $this['form']->setDefaults([
            'multiplier' => [
                '0' => ['text' => 'sorry'],
                '1' => ['text' => 'jako']
            ]
        ]);
    }

    protected function createComponentForm()
    {
        $form = new Nette\Application\UI\Form;
        $copies = 0;
        $maxCopies = 10;

        $multiplier = $form->addMultiplier('multiplier', function (Nette\Forms\Container $container, Nette\Forms\Form $form) {
            $container->addText('text', 'Text');
        }, $copies, $maxCopies);

        $multiplier->addCreateButton('Add')
                ->addClass('btn btn-primary');
        $multiplier->addRemoveButton('Remove')
                ->addClass('btn btn-danger');

        return $form;
    }

Containers are created when component is attached to presenter :/ I didn't found better solution...

https://github.com/WebChemistry/forms-multiplier/blob/master/src/Multiplier.php#L96-L126

Yeah, I guess I try create "replicator" from clear table to get deeper look. Thanks for answer, if I find some solution I will share her.