PHPackages                             lifo/autocomplete-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. lifo/autocomplete-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

lifo/autocomplete-bundle
========================

Symfony Autocomplete Form Bundle

v2.1.2(8mo ago)03.8k1MITPHP

Since Sep 30Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/lifo101/autocomplete-bundle)[ Packagist](https://packagist.org/packages/lifo/autocomplete-bundle)[ RSS](/packages/lifo-autocomplete-bundle/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (11)Used By (0)

Introduction
------------

[](#introduction)

This is a [Symfony](https://symfony.com/) Bundle that provides an autocomplete Form Type. This was designed for Symfony v4+. Currently, this widget uses [Select2](https://select2.org/) as its base. In the future I might add other 'autocomplete' widgets using different interfaces.

This is a replacement for my older [Typeahead](https://github.com/lifo101/typeahead-bundle) Bundle that was originally for Symfony v2 and hasn't been updated in years (but has served me well!). This is not a one-for-one replacement, but rather a more modern approach to doing things.

***I'm still working on features and ironing out some small issues.* I have not tagged any releases yet.**

### Features

[](#features)

- Supports Entity and Non-Entity lookups using a single class type.
- Supports AJAX or Array lists.
- Easily add the javascript code to your existing bundler *(webpack, etc)*, or use it directly via a `` tag.
- Support different themes like `bootstrap`.
- Supports `tagging` - The ability of adding new entities or items.
- Form types for `Select` and `Vue-Multiselect` widgets. Vue-Multiselect type is not documented yet.

### Requirements

[](#requirements)

- This bundle requires the [Select2](https://select2.org/) or [Vue-multiselect](https://vue-multiselect.js.org/)javascript and CSS code, but does not provide it directly. You must include it yourself, eg: `yarn add select2`, and add it to your webpack or other bundler configuration.
- `Select2` requires [jQuery](https://jquery.com/) and is not actually provided in this bundle. You must provide it yourself, eg: `yarn add jquery`

### Examples

[](#examples)

*Note: The examples below use the `bootstrap` theme from the NPM package `select2-bootstrap-theme` (`yarn add select2-bootstrap-theme`).*

A simple select box that allows a single entity `User` to be selected from an AJAX request.

[![Single Entity Selection Example (A)](src/Resources/doc/img/single_user.png)](src/Resources/doc/img/single_user.png)[![Single Entity Selection Example (B)](src/Resources/doc/img/single_user_b.png)](src/Resources/doc/img/single_user_b.png)

```
use Lifo\AutocompleteBundle\Form\Type\Select2Type;

$builder->add('user', Select2Type::class, [
    'route'            => 'users_lookup',
    //'url'              => '/absolute/url/instead/of/route',
    'min_input_length' => 1,
    'placeholder'      => 'Search for user ...',
]);
```

A simple select box that allows a multiple `User` entities to be selected from an AJAX request.

[![Multiple Entity Selection Example](src/Resources/doc/img/multiple_users.png)](src/Resources/doc/img/multiple_users.png)

```
$builder->add('users', Select2Type::class, [
    'route'            => 'users_lookup',
    'min_input_length' => 1,
    'multiple'         => true,
    'placeholder'      => 'Search for user ...',
]);
```

A simple select box that uses a plain array of choices.

[![Single Array Selection Example](src/Resources/doc/img/single_array.png)](src/Resources/doc/img/single_array.png)

```
$builder->add('status', Select2Type::class, [
    'help_block' => 'Inactive users cannot login.',
    'choices'    => [
        'Active'   => 1,
        'Inactive' => 0,
    ],
]);
```

Configuration
-------------

[](#configuration)

There are a lot of options to customize the way the autocomplete widget functions. Defaults are shown. Note: A `route`, `url`, or `choices` must be specified for the widget to function.

OptionDefaultDescription**route**`null`Symfony route name to generate an URL to perform an AJAX search request.**route\_params**`null`Parameter array to generate the `route`**url**`null`An absolute URL to perform the AJAX search request from instead of a `route` name.**choices**`null`An keyed array of choices to populate the select box with instead of using AJAX.**class**`null`The Entity class representing the items in the results. Can be `null` to use non-entities.**property**`"id"`The unique ID property name to use for the `id` of each item.**text\_property**`null`The property to render the selection text from. Can be `null` if your Entity has a `__toString` method.**multiple**`false`If true, multiple items can be selected.**min\_input\_length**`0`Minimum input length required before a search request is performed.**max\_selections**`0`Maximum selections allowed (`multiple` is true). Set to `0` for no limit.**delay**`250`Delay, in milliseconds before a search request is performed.**tags**`false`Enable `tagging` support (adding new entries).**placeholder**`null`Placeholder text shown in the widget when nothing is selected.**allow\_clear**`true`Allow the selection(s) to be cleared with a single click of an "x" icon.**close\_on\_select**`true`Close the dropdown after a selection is made.**theme**`"bootstrap"`Theme to use. 'default' is the standard option for Select2.**language**`"en"`Lanuage to use.**dropdown\_auto\_width**`false`If true, the dropdown width will expand to its contents.**dropdown\_parent**`null`CSS Selector target for the dropdown parent placement. Useful if you need to target a modal, etc.**dir**`"ltr"`Language direction: Left-to-Right (rtl), or Right-to-Left (ltr)**disabled**`false`If true, the select will be disabled.**transformer**`null`Custom `DataTransformer` to use.Installation
------------

[](#installation)

### Symfony v4+, v5+, v6+

[](#symfony-v4-v5-v6)

`composer require lifo/autocomplete-bundle`

If you're using [Flex](https://symfony.com/doc/current/setup/flex.html) then the bundle will work w/o any other configuration.

If you're not using `Flex` then you'll need to register the bundle in `bundles.php`:

```
// config/bundles.php
return [
    // ...
    Lifo\AutocompleteBundle\LifoAutocompleteBundle::class => ['all' => true],
    // ...
];
```

### Twig Configuration

[](#twig-configuration)

By default, the form theme is enabled automatically in Twig, but you can disable this if you need to with the following config:

```
lifo_autocomplete:
  autoconfigure: false
```

If `autoconfigure` is disabled, you'll have to manually update your Twig config:

```
    # config/packages/twig.yaml
    form_themes:
        - '@LifoAutocomplete/autocomplete.html.twig'
```

### Symfony v3.x

[](#symfony-v3x)

Symfony v3 is not officially supported, but might work if you manually register the bundle in `app/AppKernel.php`

```
$bundles = array(
  // ...
  new Lifo\AutocompleteBundle\LifoAutocompleteBundle(),
);
```

### Webpack

[](#webpack)

This is an example of how to add the javascript and CSS to your app. The concept here is similar to other bundlers as well.

In your main entry point you would add something similar as this:

```
// assets/app.js
import 'bootstrap'
import 'select2'
require('select2/dist/css/select2.min.css');
// ...
```

### Script Tag

[](#script-tag)

You can include the required javascript by using straight script tags too. The paths here assume the files are already in your `public` web directory.

```

```

Data Format
-----------

[](#data-format)

AJAX responses and the simple Array lists require the following format:

```
[
  'results' => [
    [
      'id'   => 'unique ID',
      'text' => 'text displayed',
    ],
    [
      'id'   => 'unique ID',
      'text' => 'text displayed',
    ],
  ],
  'more' => true|false,
  // or:
  // 'pagination' => [
  //   'more' => true|false
  // ]
```

AJAX Requests
-------------

[](#ajax-requests)

`Select2` sends the following on [AJAX requests](https://select2.org/data-sources/ajax#request-parameters).

- **`term`** - The current search term in the search box.
- **`q`** - Contains the same contents as `term`.
- **`_type`** - "request type". Will usually be query, but changes to query\_append for paginated requests.
- **`page`** - The current page number to request. Only sent for paginated (infinite scrolling) searches.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance61

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~117 days

Recently: every ~112 days

Total

10

Last Release

263d ago

Major Versions

v1.2.1 → v2.02024-12-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/367337?v=4)[Jason M](/maintainers/lifo101)[@lifo101](https://github.com/lifo101)

---

Top Contributors

[![lifo101](https://avatars.githubusercontent.com/u/367337?v=4)](https://github.com/lifo101 "lifo101 (25 commits)")

### Embed Badge

![Health badge](/badges/lifo-autocomplete-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/lifo-autocomplete-bundle/health.svg)](https://phpackages.com/packages/lifo-autocomplete-bundle)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
