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.1.2 2018-10-21 16:23 UTC

This package is auto-updated.

Last update: 2024-03-24 14:46:33 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();
            }
        ));