Skip to content

[Form] DefaultChoiceListFactory::flatten disrespects choices with same label different value #15181

Closed
@alaczi

Description

@alaczi

With Form version 2.7+

Imagine a situation of an expanded grouped choice field:

$choices = array(
    'light' => array(
        'blue' => 'lightblue',
        'red' => 'lightred'),
    'dark' => array(
        'blue' => 'darkblue',
        'red' => 'darkred')
    );
$builder
    ->add('colors', 'choice', array(
        'choices' => $choices,
        'label' => false,
        'expanded' => true,
        'multiple' => true,
        'choices_as_values' => true,
    ));

With some templating magic you can come up something like this (and so, there is a reason to use grouping with expanded choices)..

grouped_expanded_choice_list

Now, the problem is that DefaultChoiceListFactory::flatten will merge the darkblue and lightblue into the same value key (both checkboxes will have the value="0") and upon postback the third checkbox value will be lightblue instead of the properly selected darkblue.
This concept works well with Symfony Form 2.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions