Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post data not available #45

Closed
driici opened this issue Mar 2, 2020 · 6 comments
Closed

post data not available #45

driici opened this issue Mar 2, 2020 · 6 comments

Comments

@driici
Copy link

driici commented Mar 2, 2020

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?

@MartkCz
Copy link
Member

MartkCz commented Mar 30, 2020

How form looks?

@driici
Copy link
Author

driici commented Mar 30, 2020

  $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}

@MartkCz
Copy link
Member

MartkCz commented Mar 30, 2020

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

@driici
Copy link
Author

driici commented Apr 1, 2020

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

@MartkCz
Copy link
Member

MartkCz commented Apr 4, 2020

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?

@driici
Copy link
Author

driici commented Apr 4, 2020

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.

@MartkCz MartkCz closed this as completed in e3a337b Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants