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

Missing support for `createOne` #31

Closed zeleznypa closed 6 years ago

zeleznypa commented 6 years ago

There is method createOne in Kdyby/FormsReplicator that allow to work with containers by your own.

In our project there is something like:

<?php

namespace App;

use Nette\Application\UI\Form;

class TestForm extends Form {

    public function __construct() {
        $this->addDynamic('params', function(Container $container) {
            $container->addText('name', 'Název obecného parametru');
        }, 0);
    }

    public function loadParams() {
        $params = [
            'Parametr 1',
            'Parametr 2',
            'Parametr 3',
        ];

        foreach ($params as $id => $name) {
            $container = $this['params']->createOne($id);
            $container['name']->caption = $name;
        }
    }

}

There is method addCopy in WebChemistry/Multiplier that work almost same.

But it is protected.

Will it be possible to make this method public by default?

Or,is there any other way for manually adding values in dynamic container and work with each one?

MartkCz commented 6 years ago

Can you send whole code? or you can use setDefaults method

zeleznypa commented 6 years ago

It is not about values but about working with Container. For example, when you want to change caption of the generated inputs in container. Or when you want to add specific form rules based on inserted parameters.

MartkCz commented 6 years ago

Usage:

    $multiplier->onCreateComponents[] =[$this, 'loadParams'];

    public function loadParams(Multiplier $multiplier) {
        $params = [
            'Parametr 1',
            'Parametr 2',
            'Parametr 3',
        ];

        foreach ($params as $name) {
            $container = $multiplier->addCopy();
            $container['name']->caption = $name;
        }
    }
zeleznypa commented 6 years ago

🙇