Autocomplete upload widget and form type for Symfony
This package provides:
an almost dependency-free autocomplete source API, with a generic controller that should be suitable for most frameworks,
a Symfony bundle that brings a form widget, source registration, and the associated controller for autocompleting things into forms.
You have two fixes to make:
First one is that the
AutocompleteSourceInterface::find()method query argument typing changed, you must adapt your sources.
Second is that we now support more libraries than only
select2, so instead of including
AutocompleteBundle:Form:fields.html.twigyou must chose either one of
Template engine based rendering has been dropped, it's up to you to implement it properly in your sources.
composer require makinacorpus/autocomplete-bundle
- a container with the
.tac-containerCSS class, for being more precise in selecting the component,
- both will have the
data-tac-idattribute (which yield the same value for both inputs) and the
data-tac-roleattribute, which respectively yield the
text input also yield the
data-autocomplete-uri which contains a
generated URL for querying data (please note that URL can change in time, for
security or deduplication reasons). In order to query this URL you can use the
following query parameters:
querywhich holds the user input,
limitwhich holds the number of items to fetch,
pagepage number (which starts at
Once you get results, and the user selects a value, you must set the return
id property into the
[data-tac-role="id"] element, and the object
label property into the
Bonus point if you empty the hidden value when the users manually edit the text value.
If you use
select2 you also need
jQuery to be installed (any version).
Register the routing.yml file in your
autocomplete: resource: "@AutocompleteBundle/Resources/config/routing.yml" prefix: /
And the associated form theme in your
twig: debug: "%kernel.debug%" strict_variables: false form_themes: # For select2 based widget: - "AutocompleteBundle:Form:fields-select2.html.twig"
Beware that this method is not supported anymore, it might work, it might not.
First, implement an
class, that is meant to reflect the business objects in which to autocomplete.
Then just use the
MakinaCorpus\AutocompleteBundle\Form\Type\TextAutocompleteType form type
in your own form builders, and set the source class name as the
source parameter for the form type.