Ajax request

Hello. I have a input tab.




 <?php echo CHtml::textField('name', '', array('id'=>'playerName'));?>



I want to show autoComplete list of players’ names by ajax request when user start typing on the input tab like google.

Help me to this please.

Dear Dijgee,

Just replace the following




 <?php echo CHtml::textField('name', '', array('id'=>'playerName'));?>



with




<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(

      'name'=>'name',

      'source'=>array('name1','name2','name3'....),//or Define a method to get the data from database

      'options'=>array(

          'minLength'=>'2' ),

  )); ?>



Once you submit the form, you can get the selected name from $_POST[‘name’].

regards.

Thank you.

What if i like to user CActiveRecord array as a source?

Hello,

You can get an array of datas from CActiveRecord like below




<?php

$C = new CDbCriteria;

$C->select = "title";

$data = CActiveRecord::model()->findAll($C);

?>



Or if more complicated you can use ajax calls to get datas (and then do whatever you need to) with parameters sourceUrl

Regards