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

post data not available

driici opened this issue · comments

Hi,
I have current (9afdae2) version and have problem with accessing form data. When I dump($_REQUEST) I see everything was submitted via request. Hovever if I want to access multipliers items via $form->getValues()->multiplier there is no data. My multiplier has name variants:

$_REQUEST:
variants => 0 => rarity => "1" value => "500" text => "text"

$form->getValues():
variants => Nette\Utils\ArrayHash #1462

$form->getComponent("variants")->getComponents():
Nette\ComponentModel\RecursiveComponentIterator #ca3d

Did I miss something in documentation, badly register it or just simply replicator is not compatible with nette/3.0?

How form looks?

  $form->addGroup("Variants")
        ->setOption("id", "variants");

    $multiplier = $form->addMultiplier(
        'variants',
        function (Container $container) use ($rarities) {
            $container->addSelect("rarity", "Rarity", $rarities);
            $container->addText("value", "Value")->setDefaultValue("x");

            $container->addTextArea("text", "Text", NULL, 10);
            bdump($container);
        },
        1,
        10
    );

    $multiplier->addCreateButton('Add')
        ->addClass('btn btn-primary ajax');

    $multiplier->addRemoveButton('Remove')
        ->addClass('btn btn-danger ajax');

    $form->addGroup("");

    $form->addSubmit("s", "Save");

and in latte:
{snippet form}
{control form}
{/snippet}

What returns this $form->getHttpData()? Is $form instance of UI\Form?

Yes form is instance of UI\From.
$form->getHttpData() strangely contains data posted via form:

variants => 
0 => 
rarity => "1"
value => "x"
text => "x"
1 => 
rarity => "1"
value => "x"
text => "asdsd"

But $form->getValues() emprty variants

I tried following code

		$form = new Form();

		$form->addGroup("Variants")
			->setOption("id", "variants");

		$multiplier = $form->addMultiplier(
			'variants',
			function (Container $container) {
				$container->addSelect("rarity", "Rarity", ['one', 'two']);
				$container->addText("value", "Value")->setDefaultValue("x");

				$container->addTextArea("text", "Text", NULL, 10);
				bdump($container);
			},
			1,
			10
		);

		$multiplier->addCreateButton('Add')
			->addClass('btn btn-primary ajax');

		$multiplier->addRemoveButton('Remove')
			->addClass('btn btn-danger ajax');

		$form->addGroup("");

		$form->addSubmit("s", "Save");
		
		$form->onSuccess[] = function ($form, $values) {
			bdump($form->getValues());
			bdump($values);
		};

		return $form;

and nette dumps correct values. Where do you dump the values?

OK I think I found a problem. Not sure on whose side...
When form is constructed with $form = new \Nette\Application\UI\Form; then multiplier works as expected for me. However when I use \Nette\Application\UI\Form($this, $name); as constuctor (see two parameters) I hot an empty array for variants.