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

Symfony\Component\DomCrawler\Field\ChoiceFormField should accept selecting by content #51423

Copy link
Copy link
Open
@tarjei

Description

@tarjei
Issue body actions

Description

If I got a formfield like:

$form->add('status', ChoiceType::class, [
    'label' => 'Status',
    'choices' => [
        'error' => 'Error',
        'ok' => 'This is ok'
    ]
]);

Then in my test I should be able to do:

$form = $crawler->form();
$form['form[status]']->selectByText('This is ok');

Today I must do this by having an outside algorithm:

private function formSelectChoose(ChoiceFormField $formField, string $value, Crawler $crawler )
{
    $name = $formField->getName();
    $select = $crawler->filter('select[name="'.$name.'"]')->first();
    foreach($select->filter('option') as $option) {
        print $option->textContent ."\n";
        if (trim($option->textContent) == $value) {
            $formField->select($option->getAttribute('value'));
            return;
        }
    }
    throw new \Exception("Could not find option $value");
}

It would be great to be able to do this directly on the ChoiceFormField.

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.