typeahead-js bundle
This bundle provide typeahead.js form type integration into a Symfony project., (*1)
Instalation
Install with composer:, (*2)
$ composer require mapado/typeaheadjs-bundle
Update your app/AppKernel.php file:, (*3)
$bundles = array(
// ...
new Mapado\TypeaheadJsBundle\MapadoTypeaheadJsBundle(),
);
Update your app/config/config.yml file to provide twig form template:, (*4)
twig:
form:
resources:
- 'MapadoTypeaheadJsBundle:Form:fields.html.twig'
Use your assets manager to include this file: Resources/public/js/typeahead-form.js, (*5)
Usage
Usage is very simple:, (*6)
$builder->add('user', 'typeahead', [ 'url' => $searchUrl ]);
You need to pass the $searchUrl as a parameter., (*7)
Ajax response
The response must be a JSON array in the following format:, (*8)
[
{ "id": 1, "value": "Foo" },
{ "id": 2, "value": "Bar" }
]
Note
This bundle is greatly inspired by Lifo101 typeahead bundle but it does work with the typeahead-js new version of typeahead., (*9)
It does not requires bootstrap, and supports a lot less features for now., (*10)
Feel free to make a PR or open an issue if you want to add stuff., (*11)