CAutoComplete with associative array as data

From the class reference for CAutoComplete:


public array $data;

data that would be saved as client-side data to provide candidate selections. Each array element can be string or an associative array. The url property will be ignored if this property is set.

But when I try:

<div class="yiiForm">

<?php echo CHtml::form(); ?>


$data = array('a'=>'The A String', 'b'=>'The B String');

echo $this->widget('CAutoComplete', array('name'=>'acname', 'data'=>$data));



</div><!-- yiiForm -->

It just renders a textbox with no autocompletes. It works fine if $data is an array of stings.


The documentation is not very clear. It says each array element can be an associative array, instead of the whole array is an associative array. Therefore, you should provide something like:


   array('name'=>'test', 'email'=>''),

   array('name'=>'test1', 'email'=>''),


Using this data format, you will need to manipulate the data using javascript. More details should be found at the autocomplete's official website.

Thanks again, I'll look into it. The documentation might be a little clearer if:


Each array element can be string or an associative array.

is replaced with something like:


data can be either an array of string elements or an array of associative arrays.