Closed
Description
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