Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Selecting multiple values for a select with the Form Crawler no longer works #5562

Copy link
Copy link
Closed
@greg0ire

Description

@greg0ire
Issue body actions

This used to work before migrating to 2.1:

        $form = $crawler->selectButton('Créer')->form(array(
            'uc_legalbundle_countrygrouptype[name]'  => 'Peninsule iberique',
            'uc_legalbundle_countrygrouptype[countries]' => array('ES','PT'),
        ));

Now, it gives me the following stack trace:

1) Uc\LegalBundle\Tests\Controller\CountryGroupControllerTest::testCompleteScenario
InvalidArgumentException: Unreachable field "0"

/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:459
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:496
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:500
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Form.php:74
/home/users/gparis/workspace/legal-backend/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:650
/home/users/gparis/workspace/legal-backend/src/Uc/LegalBundle/Tests/Controller/CountryGroupControllerTest.php:23

"0" refers to the first key of this array: array('ES', 'PT')

Selecting a single value can still be done, like this:

        $form = $crawler->selectButton('Créer')->form(array(
            'uc_legalbundle_countrygrouptype[name]'  => 'Peninsule iberique',
            'uc_legalbundle_countrygrouptype[countries]' => 'ES',
        ));

The form still works in the frontend, here is the code:

<?php

namespace Uc\LegalBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\CountryType;

class CountryGroupType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('countries', new CountryType(), array(
                'multiple' => true,
                'attr' => array('data-placeholder' => 'select.default_text')))
        ;
    }

    public function getName()
    {
        return 'uc_legalbundle_countrygrouptype';
    }

    public function getDefaultOptions(array $options)
    {
        return array('data_class' => 'Uc\LegalBundle\Entity\CountryGroup');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.