Symfony: How to check the form collection type field field in a functional test without JavaScript?

I am now struggling with the collection form. I have a collection of at least 3 forms included. But since the included forms are not displayed, I can’t fill them out in a functional test.

Here is the collection

->add('references', 'collection', array(
            'type'        => 'reference',
            'allow_add'   => true,
            'constraints' => array(
                new C\Count(array(
                    'min'        => 3,
                    'minMessage' => 'You should specify at least 3 references.'
                ))
            )
        ))

And when this form is visualized, it looks like

<label class="required">References</label><div id="form_references"
data-prototype="here-is-the-rendered-prototype-of-embedded-form">

How can I get Symfony Form to render a couple of inline forms without using javascript so that I can easily test them functionally or use them in a browser without activating JS?

One more thing: forms are not attached to Enity / Model, but simply represent a simple array.

+3
source share
1 answer

. , , , - , , Symfony javascript....

http://symfony.com/doc/current/cookbook/form/form_collections.html

, .

class ApplicationController extends Controller
{
    public function newAction(Request $request)
    {
        $app = new Application();

        for ($i = 0; $i < 3; $i++) {
            $app->getReferences()->add(array(
                'name' => 'Michael ' . $i,
                'phone' => '1 (555) 555-5555'
            ));
        }

        $form = $this->createForm(new ApplicationForm(), $app);
        if ($request->getMethod() === "POST")
        {
            $form->handleRequest($request);
            if ($form->isValid()) {
                // Process and Save the information.
            }
        }

        return $this->render('AppBundle::Application:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }
}

, .

{{ form_start(form) }}

    <h3>References</h3>
    <div class="references">
        {% for reference in form.references %}
            <p>
                {{ form_row(reference.name) }}
                {{ form_row(reference.phone) }}
                {{ form_row(reference.body) }}
            </p>
        {% endfor %}
    </div>

{{ form_end(form) }}

... , , , .

+2

All Articles