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

SetDefaults with UI/Form #37

Closed kravcik closed 5 years ago

kravcik commented 5 years ago

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

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

kravcik commented 5 years ago

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.