Timwi
Timwi

Reputation: 66573

Embedding a collection of forms for an entity called “Button”: the prototype contains a wrong form

I’m trying to create a form that contains within it a collection of subforms.

The entity type for the inner form is called Button. For this example, let’s pretend that it has only one property, x, which is an integer.

So I defined this ButtonType class for the inner form:

class ButtonType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('x', 'integer');
    }
}

Now I tried to follow the instructions in How to Embed a Collection of Forms. In particular, it contains the following example code:

<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
    ...
</ul>

In their example, the inner Entity is called “tags”, so I replaced “tags” with “buttons” appropriately.

Then I added the JavaScript that adds a new subform in response to a link click.

The problem is that the data-prototype value looks like this (for better readability, I’ve unescaped it here):

<button type="button" id="storypunkt_buttons___name__" name="storypunkt[buttons][__name__]">__name__label__</button>

(“Storypunkt” is the name of the outer entity containing the collection.)

This makes no sense. Why does it render a button, and only a button? It should surely render an integer textfield for the x property. How do I fix this?

Upvotes: 2

Views: 30

Answers (1)

Timwi
Timwi

Reputation: 66573

Just for the sake of experiment I renamed it to something else (without changing anything else) and that made it work.

So the answer is as simple as it is stupid: You can’t call your entity Button.

Upvotes: 2

Related Questions