Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
disceney opened this issue Jun 6, 2024 · 5 comments
Closed

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

disceney opened this issue Jun 6, 2024 · 5 comments

Comments

@disceney
Copy link

disceney commented Jun 6, 2024

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

@smnandre
Copy link
Member

smnandre commented Jun 6, 2024

Would that looks like this ?

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

@disceney
Copy link
Author

disceney commented Jun 7, 2024

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

@nina-alin
Copy link

Hey @disceney ! Saw you closed this issue. Did you find any solutions? I am also looking to build an autocomplete like this.

@antoine1003
Copy link

@nina-alin This solution worked well form me : https://florentdestremau.bearblog.dev/using-symfony-autocomplete-to-create-entities-on-the-fly-in-a-form/

@nina-alin
Copy link

Yeah I ended up following this documentation too. Works pretty well 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants