lla/autocomplete-form-bundle

Extend Doctrine's entity form type for autocompletion support via form event and custom entity loader exposed as 'autocomplete' form type

1.0.8 2017-08-13 16:31 UTC

README

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require lla/autocomplete-form-bundle "~1"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new LLA\AutocompleteFormBundle\LLAAutocompleteFormBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Use the form type

You can use the form as normal form usage. See FormComponent

<?php
// src/AppBundle/Controller/TestController.php

// ...
class TestController extends Controller
{
    public function indexAction()
    {
        // ...
        $form = $this->createForm('form_name', 'autocomplete', array(
            'class' => 'AppBundle:YourEntity',
            'max_result' => 10, // Initial options length
            'query_builder' => function(EntityRepository $repo) {
                return $repo->createQueryBuilder();
            }
        ));