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

Can't use addConditionOn() when creating Multiplier #14

Closed foxycode closed 7 years ago

foxycode commented 7 years ago

Code:

$disks = $form->addMultiplier('disks', [$this, 'addDisk'], 0);

public function addDisk(Container $container): void
{
    $container->addText('size', 'Size')
        ->addConditionOn($container->form['brand'], Form::EQUAL, 'kvm')
            ->setRequired();
}

Error:

Nette\InvalidStateException
Component '' is not attached to 'Nette\Forms\Form'.
MartkCz commented 7 years ago

You can try this:

$disks = $form->addMultiplier('disks', [$this, 'addDisk'], 0);

public function addDisk(Container $container, Form $form): void
{
    $container->addText('size', 'Size')
        ->addConditionOn($form['brand'], Form::EQUAL, 'kvm')
            ->setRequired();
}
foxycode commented 7 years ago

@MartkCz Great, it's working :) Maybe this should be in docs. I have feeling that I dealt with this earlier.