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

[Form] choices_as_value not working properly with associative arrays #14377

Copy link
Copy link
Closed
@soullivaneuh

Description

@soullivaneuh
Issue body actions

By following the upgrade to 2.7 documentation, I'm changing choice options.

With the given form:

->add('environment', 'choice', [
    'choices'       => [
        'production'    => 'Production',
        'beta'          => 'Beta',
        'development'   => 'Development',
        'binpkg'        => 'BinPkg',
    ],
])

We get this output:

<select>
    <option value=""></option>
    <option value="production">Production</option>
    <option value="beta">Beta</option>
    <option value="development">Development</option>
    <option value="binpkg">BinPkg</option>
</select>

If I try to reverse choices and use choices_as_value option:

->add('environment', 'choice', [
    'choices'       => [
        'Production'    => 'production',
        'Beta'          => 'beta',
        'Development'   => 'development',
        'BinPkg'        => 'binpkg',
    ],
    'choices_as_values' => true,
])

I got this:

<select>
    <option value=""></option>
    <option value="0">Production</option>
    <option value="1">Beta</option>
    <option value="2">Development</option>
    <option value="3">BinPkg</option>
</select>

As you can see, my associated array keys are simply ignored and replaced by numeric values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.