Yii Framework Forum: Jquery CAutoComplete formatItem - Yii Framework Forum

Jump to content

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

Jquery CAutoComplete formatItem Rate Topic: -----

#1 User is offline   Equ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-November 09
  • Location:Russia, Moscow

Posted 18 December 2009 - 12:24 PM

Can anyone please provide some examples how to use cautocomplete formatItem and formatResult property?

Thank you!
0

#2 User is offline   Equ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-November 09
  • Location:Russia, Moscow

Posted 18 December 2009 - 03:19 PM

Ok. I've solved my problem. But seems like there is a bug in CAutoComplete formatItem or I'm doing something wrong.

In the documentation for formatItem property it says:

Quote

a javascript function that provides advanced markup for an item. For each row of results, this function will be called. The returned value will be displayed inside an LI element in the results list. Autocompleter will provide 4 parameters: the results row, the position of the row in the list of results (starting at 1), the number of items in the list of results and the search term. The default behavior assumes that a single row contains a single value.


The last parameter "search term" returns exactly the same as the first one "the results row".

Here is the code:
      <?php
			$this->widget('CAutoComplete',
				array(
				 'name'=>'cn',
				 'url'=>array('search/suggestcharacter'), 
				 'minChars'=>1,
				 'delay'=>1500,
				 'matchCase'=>false,
				 'htmlOptions'=>array('size'=>'28','class'=>'search-field'),
				 'cssFile'=>false,
				 'width'=>'310px',
				 'scroll'=>false,
				 'formatItem'=>"function(result, i, num, term) { return result + '(' + term + ')'; }",
				 ));
			?>


In the code above result is the same as term. So in my sample search for "New" the results look like:

New Jersey (New Jersey)
New York (New York)
etc.

instead of

New Jersey (New)
New York (New)
etc.


Am I doing something wrong or it's a bug?


P.S. I don't really need it for my project, just asking out of curiosity.
0

#3 User is offline   Equ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-November 09
  • Location:Russia, Moscow

Posted 19 December 2009 - 11:25 AM

Hello, people! Two topics and no answers? What's going on here? :)
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