Skip to content

Feature Request: Add group_by and choice_label options to CrudAutocompleteType #7419

@ahmed-bhs

Description

@ahmed-bhs

Description

Currently, when using AssociationField::autocomplete(), it's not possible to use the group_by and choice_label form type options that are available in Symfony's standard EntityType.

This limits the UX possibilities when dealing with large datasets that would benefit from visual grouping in the autocomplete dropdown.

Use Case

I have an entity Issue that belongs to a RedmineProject. When selecting issues in a form, I would like to:

  1. Group issues by their parent project using group_by
  2. Customize the label using choice_label to avoid redundancy (since the project name is already visible in the group header)

Example of what I'm trying to achieve:

$issues = AssociationField::new('issues', 'issues')
    ->setFormTypeOption('group_by', fn (Issue $issue) => $issue->getProject()?->getName() ?? 'No project')
    ->setFormTypeOption('choice_label', fn (Issue $issue) => "[{$issue->getId()}] {$issue->getName()}")
    ->autocomplete();

Current Behavior

When using autocomplete(), the following error is thrown:

An error has occurred resolving the options of the form "EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudAutocompleteType":
The options "choice_label", "group_by" do not exist.

Expected Behavior

The CrudAutocompleteType should support group_by and choice_label options, similar to Symfony's EntityType, allowing developers to:

  • Group autocomplete results visually
  • Customize how each option is displayed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions