EasyAdminBundle
EasyAdminBundle copied to clipboard
ChoiceField with Enum renders twice with identical key-value pair
Describe the bug When creating a ChoiceField using a Enum where the "key and value" are exactly the same (case sensitives), the enum gets rendered twice.
To Reproduce Create a EasyAdmin crud dashboard, add an entity with an enum and give it the same keys and values. See repository below.
(OPTIONAL) Additional context Symfony 6.4 EasyAdmin 4.8.11 PHP 8.3.1
It's not a bug at all. Take a look at setChoices method.
// you can set the options as all the possible cases of the Enum explicitly
yield ChoiceField::new('status')->setChoices(ExampleEnum::cases());
You can also refactor Your entity.
#[Entity]
class Entity
{
#[Column(type: 'string', enumType: ExampleEnum::class)]
public $status;
}
and than
// there's no need to call ->setChoices(); EasyAdmin will get all possible values via Doctrine; it's equivalent to calling: ->setChoices(ExampleEnum::cases())
yield ChoiceField::new('status');
Closing as fixed in #6163.