genemu / GenemuFormBundle

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

genemu autocompleter (entity) + type: annotation #395

Open Raug opened 9 years ago

Raug commented 9 years ago

Hello everyone,

i'm trying to implement an autocompleting field in a symfony form 2 using the genemu bundle.

i'm trying to follow the instructions given in the documentation and on this issue : http://stackoverflow.com/questions/26518405/symfony2-autocomplete-form-bundle

But as soon as i try to add the type : annotation line, i get a 500 error and i can't figure out why.

here's routing.yml


etat_stock_ajaxcommande:
    defaults: { _controller: EtatStockBundle:Export:ajaxcommande }
    pattern: /ajaxcommande/
    type:     annotation

the controller :


use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

...->add('member', 'genemu_jqueryautocompleter_entity', array(              
                                'class' => 'EtatStockBundle:Flux',
                                'route_name' => 'etat_stock_ajaxcommande',
                                'property' => 'codeArticle',
                                // 'multiple' => true
                            ))

/**
     * @Route("/ajaxcommande/", name="etat_stock_ajaxcommande")
     */
    public function ajaxcommandeAction(Request $request) {

        $value = $request->get('id');

        $commande = $this->getDoctrine()
                        ->getManager()
                        ->getRepository('EtatStockBundle:Flux')
                        // ->findAjaxValue($value);
                        ->findAll();

        $json = array();
        foreach ($commande as $commande) {
            $json[] = array(
                'label' => $commande->getCodeArticle(),
                'value' => $commande->getCodeArticle()
            );
        }

        $response = new Response(json_encode($json));
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    }

and layout.html.twig


{% block stylesheet %}
    ....
    {% if form is defined %}
      
      {{ form_stylesheet(form) }}
    {% endif %}
  {% endblock %}
  ...
  {% block scripts %}
    ...
    {% if form is defined %}
      
      
      {{ form_javascript(form) }}
    {% endif %}
  {% endblock %}

if i go directly to the ajaxcommande route in my browser, i can see very entry listed correctly until i use the anootation type.

if i comment the type:annotation the site loads although the autocompleter doesn't work.

Any idea what could be the problem ? If the autocompleter needs the type : annotation then the error comes from the fact that i can't use them for now. If not then it doesn't work as is and i don't know why...

Thanks in advance,

Raug