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

Multiple form with same EntityType with different choice_value #42206

Copy link
Copy link
Closed
@vodkhard

Description

@vodkhard
Issue body actions

Symfony version(s) affected: 5.2
Description
Got an error when I submit two differents Form with the same EntityType but not the same 'choice_value'
"Unable to reverse value for property path "foo": The choice "1" does not exist or is not unique."

How to reproduce

$form1 = $this->createFormBuilder(null, ['allow_extra_fields' => true])->add('foo', EntityType::class, [
    'class' => Foo::class,
    'choice_value' => 'code'
])->getForm();
$form1->submit([
    'foo' => 123
]);

$f = $this->createFormBuilder(null, ['allow_extra_fields' => true])->add('foo', EntityType::class, [
    'class' => Foo::class,
    'choice_value' => 'id',
])->getForm();
$f->submit([
    'foo' => 1
]);`

with a Foo entity like this :

class Foo {
    /**
    * @ORM\Column(name="id", type="integer")
    * /
    private $id;
    
    /**
    * @ORM\Column(name="code", type="integer")
    * /
    private $code;
}

Possible Solution
Seems to be a problem in the Symfony\Component\Form\ChoiceList\Loader\AbstractChoiceLoader.php with the $choiceList attribute set by the first Form with key 'code' and not reset before the second Form

Additional context

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.