EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

ChoiceField with Enum renders twice with identical key-value pair

Open VincentvdRee opened this issue 1 year ago • 1 comments

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

Example Repo image

VincentvdRee avatar Jan 25 '24 20:01 VincentvdRee

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');

Macko82 avatar Feb 02 '24 16:02 Macko82

Closing as fixed in #6163.

javiereguiluz avatar Feb 26 '24 19:02 javiereguiluz