Skip to content

[Crawler] Selecting values of a ChoiceType field multiple and expanded #7337

Closed
@mmenozzi

Description

@mmenozzi

On DomCrawler documentation is stated that is possible to select many options form a multiple select or checkboxes: http://d.pr/i/uY29.

// select many options from a "multiple" select or checkboxes
$form['registration[interests]']->select(array('symfony', 'cookies'));

I found that this is not true if the choice field is expanded (so checkboxes are generated). As stated in #5562 and in #5502, I also tried with:

$form['registration[interests]']->setValues(array('symfony', 'cookies'));

But doesn't work. The problem is that $form['registration[interests]'] returns an array of ChoiceFormField (where every ChoiceFormField represent the single checkboxes of the options) so you can't call any method on it.

The only way to select values for a multiple and expanded choice field using DomCrawler is this:

$form['registration[interests][0]']->tick();
$form['registration[interests][3]']->tick();

Where 0 and 3 are zero-based indexes for the options symfony and cookies. This is uncomfortable because in tests we know the value of the choices and not the position in the markup of the correspondent checkbox.

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