CAutoComplete with associative array as data

From the class reference for CAutoComplete:

Quote

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(); ?>


<?php


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


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


?>


</form>


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


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

Thanks.

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(


   array('name'=>'test', 'email'=>'xxx@test.com'),


   array('name'=>'test1', 'email'=>'xxx@test1.com'),


);


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:

Quote

Each array element can be string or an associative array.

is replaced with something like:

Quote

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