I want my AssociationField
to display a blank value by defaut, in ordre to force the users to select an item.
As I understand, AssociationField
is based on EntityType
FormType.
My Problem is, if the field of my entity is required, the create form renders the AssociationField without empty value, and thus selects the first value.
I haven't seen any option to add a placeholder to a select for required properties.
Here are some samples:
My Doctrine entity :
//Player.php
#[ORM\ManyToOne(inversedBy: 'players')]
#[ORM\JoinColumn(name:'team_id', referencedColumnName: 'id', nullable: false)]
private Team $team;
... and my CrudController
//PlayerCrudController.php
public function configureFields(string $pageName): iterable
{
return [
//...
AssociationField::new('team'),
//...
]
}
And the create form displays a select with already a value selected.
I've looked into the docs but couldn't find how to achieve this.
Try ->setRequired(false)
, works for me with EasyAdmin 4.6.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With