Download the PHP package acseo/select-autocomplete-bundle without Composer
On this page you can find all versions of the php package acseo/select-autocomplete-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download acseo/select-autocomplete-bundle
More information about acseo/select-autocomplete-bundle
Files in acseo/select-autocomplete-bundle
Package select-autocomplete-bundle
Short Description Make Symfony form autocompletion easily
License MIT
Homepage https://github.com/acseo/select-autocomplete-bundle
Informations about the package select-autocomplete-bundle
ACSEO SELECT AUTOCOMPLETE BUNDLE
-
Table of content
- Introduction
- Installation
- Usage
- Form options
- class
- properties
- display
- strategy
- multiple
- format
- identifier
- transformer
- autocomplete_url
- provider
- Providers
Introduction
This bundle helps you to build autocomplete fields in your symfony forms without declaring any controller or action.
Fully configurable, you can override any part of the autocompletion process very easily.
Doctrine ORM & ODM are supported by default, but you can create your own providers for other extensions !
Installation
Install source code with composer :
Enable the bundle :
Use the bundle form theme globally (or locally in your templates) :
Usage:
Let's start by a simple example :
With your favorite js library, transform the rendered input to autocomplete input (example with select2) :
Please note 3 important things in this js example :
- The rendered input has a
data-autocomplete-url
attribute and the value inside can be used to retrieve search results. - The query param
q
, which represents the search terms, has to be added to data-autocomplete-url value. - By default search results are returned by entrypoint like
[{ "value": "label" }]
.
Your autocomplete is now functional !
Form options
Name | Type | Required | Default | Description |
---|---|---|---|---|
class | string | yes | null | The model class supposed to be autocompleted |
properties | string array | no | id | The properties used in database query to filter search results of autocomplete action. This properties can be nested with path like "nestedProperty.property". |
display | string callable array | no | properties | The displayable properties used to build label of selectable choices. This properties can be nested with path like "nestedProperty.property". |
strategy | string | no | contains | The strategy used to filter search results (allowed : starts_with / ends_with / contains / equals). |
multiple | bool | no | false | Is collection field. |
format | string callable | no | json | Default format used to encode choices of autocomplete response. Values allowed are provided by your own serializer (basically json / xml / csv / yaml in symfony serializer). Use callable to override encoding process. |
identifier | string | no | id | Name of your model identifier property (will be used as value of each choice option). |
autocomplete_url | string | no | request.pathInfo | The entrypoint where autocomplete results can be retrieved. By default we use the route where the form has been built. This value will be set in attribute "data-autocomplete-url" of field input. |
transformer | boolean object | no | ModelTransformer | Disable/Override the form type transformer. If this value is false, transformer deals only with the identifier(s) value(s) (useful for filters). |
provider | string callable array object | no | null | Create your own custom queries or specify a provider to use. |
Tips : You can also override any part of the process more globally by creating a class which extends AutocompleteType.
class
properties
display
strategy
multiple
format
identifier
autocomplete_url
Sometimes you will need this option to retrieve search results from specific entrypoint.
transformer
provider
Providers
Providers classes are used to retrieve search results form database and transform form view data to model object.
2 Doctrine providers are included by default : ORMDataProvider and ODMDataProvider which supports multiple db connexions.
You can create your own provider for specific model class or specific database. This is an arbitrary example :
Finally, tag this service with acseo_select_autocomplete.data_provider
.
Now, this provider will be invoked by default if it supports the given model class.
All versions of select-autocomplete-bundle with dependencies
symfony/dependency-injection Version ^3.4 || ^4.0 || ^5.0
symfony/form Version ^3.4 || ^4.0 || ^5.0
symfony/serializer Version ^3.4 || ^4.0 || ^5.0
symfony/property-access Version ^3.4 || ^4.0 || ^5.0
symfony/flex Version ^1.3.0