Skip to content

[AutoComplete] Entity Autocomplete & Add If Not Exist #1890

Closed
@disceney

Description

@disceney

Hello,

I am encountering a specific problem with Symfony UX Autocomplete.

Here's the issue:

I have an EntityType field with the attribute "autocomplete" => true. This allows me to search for an element from another table to establish a relation, and it works correctly. For example:

$formBuilder->add("fieldManyToMany", EntityType::class, [
    "required" => false,
    "multiple" => true,
    "class" => Entity::class,
    "choice_label" => "name",
    "autocomplete" => true
]);

However, this only displays the elements that already exist in the database. I would like to know if it is possible to use the Symfony UX Component to combine this functionality with the ability to add a new element via a DataTransformer.

The ideal solution would be to have:

  • A list of existing elements, while keeping the AJAX search system provided by the default plugin.
  • The ability to add a new element to the list, which would then be saved in the database upon submission.

If a solution or a similar issue has already been resolved, I would be interested, as I have tried multiple times without success. I still haven't been able to add a new element to my select. The system does not allow me to add new elements.

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions