contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework
https://contributte.org/packages/contributte/forms-multiplier.html
MIT License
26 stars 20 forks source link

Component with name 'multiplier_creator' does not exist #97

Closed zeleznypa closed 2 months ago

zeleznypa commented 5 months ago

When I need to add more than one multiplier into the form, I need to have them with different names:

$emails = $this->addMultiplier('emails', function(Container $container): void {
    $container->addText('email', 'Email');
});
$emails->addCreateButton('Add');
$emails->addRemoveButton('Remove');
<div n:multiplier="emails">
    <input n:name="email" />
</div>

But it fails on the error Component with name 'multiplier_creator' does not exist

jtojnar commented 4 months ago

I tried to reproduce it https://gist.github.com/jtojnar/0c059c4b1671a9c7348d641a2578445d but get no error.

What do you mean you want more than one multiplier? Your example contains only a single one. Could you please create a minimal reproducible example (e.g. something like the gist above)?

zeleznypa commented 2 months ago

Issue was caused by the fact that I still create forms "the old-fashioned way", i.e. I pass the parent to the constructor and then I define the content of the form (i.e. I create the definition of the multiplier including the addCreateButton call).

Since the multiplier is hooked to the Form::onRender event, the order of the call is crucial in this regard.

Thus the advice: If this error occurs, you need to move addCreateButton before parent::__construct($parent, $name);