[AutoComplete] Entity Autocomplete & Add If Not Exist
disceney opened this issue · comments
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 :)
Would that looks like this ?
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