0

I'm currently strugglin with rendering of my form type. I have an Order entity and OrderItems entity, which both have their own Type.

OrderType:

<?php

namespace App\Form;

...

class OrderType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('customerName', TextType::class, ['label' => 'Jméno a příjmení'])
            ...
            ->add('orderItems', CollectionType::class, [
                'entry_type' => OrderItemType::class,
                'required' => true,
                //'multiple' => true,
                'allow_add' => true,
                'prototype' => true,
                'by_reference' => false,
            ])
            ...
    }

    ...

}

Anyway, the form field are not rendering. I'm using {{ form_row(form.orderItems) }}, which render this:

<div><label class="required">Order items</label><div id="order_orderItems" data-prototype="<div><label class=&quot;required&quot;>__name__label__</label><div id=&quot;order_orderItems___name__&quot;><div><label for=&quot;order_orderItems___name___cake&quot; class=&quot;required&quot;>Dort</label><select id=&quot;order_orderItems___name___cake&quot; name=&quot;order[orderItems][__name__][cake]&quot;><option value=&quot;1&quot;>Vanilkový dort</option><option value=&quot;2&quot;>Amazing cake</option></select></div><div><label for=&quot;order_orderItems___name___quantity&quot; class=&quot;required&quot;>Množství</label><input type=&quot;number&quot; id=&quot;order_orderItems___name___quantity&quot; name=&quot;order[orderItems][__name__][quantity]&quot; required=&quot;required&quot; /></div></div></div>"></div></div>

I can see the form in the prototype, but I see no reason why it doesn't render.

Can anyone help me? Thanks.

//EDIT

After Thomas Bredillet's answer I made sure that I thought CollectionType will something different, than it does.

I made my form work using https://symfony-collection.fuz.org/symfony3/, downloadable on https://packagist.org/packages/ninsuo/symfony-collection.

Thanks again for your help.

1 Answer 1

1

A CollectionType give you only a prototype

Then, you must add javascript to use this prototype and create multiple forms of your collection

All is in the doc 😉 : https://symfony.com/doc/current/form/form_collections.html#allowing-new-tags-with-the-prototype

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.