symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
825 stars 297 forks source link

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

Open disceney opened 3 months ago

disceney commented 3 months ago

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:

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 :)

smnandre commented 3 months ago

Would that looks like this ?

https://ux.symfony.com/demos/live-component/product-form

disceney commented 3 months ago

Yes, that's roughly the idea. However, instead of opening a modal to add elements, it would be better to do it directly in the autocomplete select field