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

Default number of containers and remove button #18

Closed BigOHenry closed 6 years ago

BigOHenry commented 6 years ago

Hello. For example. I have 3 multipliers at one page (one form). All multipliers have 1 container by default. None of the containers has remove button (thats right). When i click on the add button on one of the multipliers, it will add and next container and it will add 1 remove button to the each container (thats right too) BUT also it will add remove buttons to all previous multipliers.

Example 1: default state:

multiplier1
-- container1 - NO remove button
multiplier2
-- container1 - NO remove button
multiplier3
-- container1 - NO remove button

I will click on add button on container1 of multiplier3 result is:

multiplier1
-- container1 - remove button
multiplier2
-- container1 - remove button
multiplier3
-- container1 - remove button
-- container2 - remove button

Example 2: default state:

multiplier1
-- container1 - NO remove button
multiplier2
-- container1 - NO remove button
multiplier3
-- container1 - NO remove button

I will click on add button on container1 of multiplier2 result is:

multiplier1
-- container1 - remove button
multiplier2
-- container1 - remove button
-- container2 - remove button
multiplier3
-- container1 - NO remove button

This is very interesting and i dont know what problem is. This behavor is only at empty inputs. When i use default values, everything is fine.

Any idea?

Thank you very much

MartkCz commented 6 years ago

Sorry for late response.

Do you have dev-master version? I think, last commit fixed this issue.

BigOHenry commented 6 years ago

Np. Yes i have dev-master version:

"webchemistry/forms-multiplier": "@dev",

MartkCz commented 6 years ago

I try this code, but I can't reproduce the error

        $form = new Nette\Application\UI\Form();

        $form['multiplier'] = $multiplier = new Multiplier(function (Nette\Forms\Container $container) {
            $container->addText('bar', 'Container 1');
        });

        $multiplier->addRemoveButton('Remove');
        $multiplier->addCreateButton('Create');

        $form['multiplier2'] = $multiplier = new Multiplier(function (Nette\Forms\Container $container) {
            $container->addText('bar', 'Container 2');
        });

        $multiplier->addRemoveButton('Remove');
        $multiplier->addCreateButton('Create');

        $form['multiplier3'] = $multiplier = new Multiplier(function (Nette\Forms\Container $container) {
            $container->addText('bar', 'Container 3');
        });

        $multiplier->addRemoveButton('Remove');
        $multiplier->addCreateButton('Create');

        $form->addSubmit('send');

        $form->onSuccess[] = function ($form, array $values) {
            Debugger::barDump($values);
        };

        return $form;
MartkCz commented 6 years ago

Can you try please version dev?