views:

177

answers:

0

Hello,

I have use a tutorial to make an input autocomplete with jQuery and ajax. But when I write something in, the circle turns to show there is a request but the list with the choices isn't display. I have tried with an entry I know it must appear in the list.

My action :

public function executeMyAction(sfWebRequest $request) {
    $this->getResponse()->setContentType('application/json');

    $string = $request->getParameter('q');
    $second_parametre = $request->getParameter('second_parametre');

    $req = Doctrine::getTable('locataire')->getDataWhere($string, $second_parametre);

    $results = array();
    foreach ($req as $result):
        $results[$result->getNud()] = $result->getNom();
    endforeach;

    return $this->renderText(json_encode($results));
  }

My model :

public function getDataWhere($string, $second_parametre) {
        $q = Doctrine_Query::create()
                    ->from('Locataire l')
                    ->where('m.nom LIKE ?', "%$string%")
                    ->orderBy('m.nom ASC')
                    ->execute()
                    ->getData();

        return $q;
    }

Making widget :

$this->widgetSchema['nom'] = new sfWidgetFormJQueryAutocompleter(array('url' => 'myAction',
                                                                               'config' => '{extraParams: { second_parametre: function() { return jQuery("#id_html").val();}},
                                                                                            scrollHeight: 250,
                                                                                            autoFill: true}'));

My form : (jQuery is already includes in my view.yml)

<?php use_javascript('/sfFormExtraPlugin/js/jquery.autocompleter.js')?>
<?php use_stylesheet('/sfFormExtraPlugin/css/jquery.autocompleter.css')?>

<tr>
    <th><?php echo $form['nom']->renderLabel() ?> :</th>
    <td><?php echo $form['nom'] ?></td>
</tr>