Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Autocomplete field in Symfony2 with the formType and Doctrine2

I got 2 entities linked by a 'OneToMany' relationship. One of the entities is the object City. The table corresponding to this object includes almost 37000 entries. When I proceed to the creation of a form to populate the Proprietairy entity in Symfony, I use a FormType which looks like below. It includes a field corresponding to the City Object

namespace Immo\BienBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class ProprietaireType extends AbstractType {
    public function buildForm(FormBuilder $builder, array $options) {
        $builder
        ->add('nom')
        ->add('prenom')
        ->add('email')
        ->add('telephone')
        ->add('adresse')
        ->add('city', 'entity', array(
            'class'=>'Immo\BienBundle\Entity\City', 
            'property'=>'city'));
    }

    public function getName() {
        return 'immo_bienbundle_proprietairetype';
    }
}

The form renders a combobox. populated by the 36000 cities and takes incredibly long to load. I have tried the option fetch="extra_lazy", but it is still not efficient enough. My idea was to create a form with an input field working with ajax and displaying the list of the cities after the user provides 2 letters. I would appreciate any help from the community to create the needed relationship with my Object when validating.

like image 973
Esteban Avatar asked Oct 27 '11 10:10

Esteban


1 Answers

Use https://github.com/symfony/symfony/pull/1951 Soon in the v2.1 I hope...

like image 123
webda2l Avatar answered Nov 15 '22 05:11

webda2l