forms-multiplier icon indicating copy to clipboard operation
forms-multiplier copied to clipboard

Component with name 'multiplier_creator' does not exist

Open zeleznypa opened this issue 1 year ago • 1 comments

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

zeleznypa avatar Feb 29 '24 12:02 zeleznypa

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)?

jtojnar avatar Mar 20 '24 22:03 jtojnar

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);

zeleznypa avatar May 21 '24 09:05 zeleznypa