genemu / GenemuFormBundle

Extra Form : Captcha GD, Tinymce, Recaptcha, JQueryDate, JQueryAutocomplete, JQuerySlider, JQueryFile, JQueryImage
587 stars 263 forks source link

Select2 and many-to-many relations #314

Closed abocquet closed 9 years ago

abocquet commented 10 years ago

Hi, I've a problem with the select2 entity form type: when I use this type for a many-to-many relation, the link between my entities is not persisted whereas it works with a simple 'entity' form

// it works
$this->form->add('eleves_entity', 'entity', array(
                'class' => 'Kub\UserBundle\Entity\Eleve',
                "multiple" => true,
                "expanded" => true,
                "property_path" => "eleves",
                'query_builder' => function(EleveRepository $er) {

                    return $er->createQueryBuilder('e')
                        ->orderBy('e.username', 'ASC')
                        ->where('e.niveau = :niveau')
                        ->setParameter('niveau', $this->data->getNiveau())
                    ;
                }
            ));

// it doesn't
            $this->form->add('eleves', 'genemu_jqueryselect2_entity', array(
                'class' => 'Kub\UserBundle\Entity\Eleve',
                "multiple" => true,
                "expanded" => true,
                'query_builder' => function(EleveRepository $er) {

                    return $er->createQueryBuilder('e')
                        ->orderBy('e.username', 'ASC')
                        ->where('e.niveau = :niveau')
                        ->setParameter('niveau', $this->data->getNiveau())
                    ;
                }
            ));

I don't think I made a mistake considering that the doc says that we "just have to prefix the type name with genemujqueryselect2* ", so it may be a malfunction of the bundle, that is, by the way, just awesome !

Thank, Adrien

cubotar commented 10 years ago

Hi thanks for sharing ... can you please give more explanation, I have a relation Many-to-Many btw a Video entity and Category entity I'm confused btw your solution and the incomplete doc explanation it gives an error when I follow the doc the error is : "Could not load type "genemu_jquerychosen_category".. thank you