Yii Framework Forum: CAutoComplete with associative array as data - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CAutoComplete with associative array as data Rate Topic: -----

#1 User is offline   brooss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 16-November 08

Posted 06 December 2008 - 02:38 AM

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.
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,895
  • Joined: 04-October 08
  • Location:DC, USA

Posted 06 December 2008 - 08:08 AM

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.
0

#3 User is offline   brooss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 16-November 08

Posted 07 December 2008 - 11:05 AM

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.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users