Little problem here: I use cjuiautocomplete and an url that returns json data for the feed (same host). The autocomplete only gives a full list of city names…so when I type: “Gelu…” he won’t show me the city names starting with “gelu”, but instead the full list. Anyone knows a fix?
controller:
class ApiController extends Controller
{
public function actionCity()
{
echo CJSON::encode($this->extractCities());
}
Can you post your extractCities() method? I think that’s where your problem is. Sounds like your search method/criteria isn’t processing the posted term.
No, it’s because when the array provided in advance, searches it client side. When you use an external action, you’re telling it that you’re going to process the list of answers yourself. This lets you do much more complex searching etc. than you can do by default.
This is an example from an autocomplete lookup we use:
/**
* @param string $term The string to match (automatically sent by the cjuiautocomplete widget)
* @param int $limit
*/
public function actionAutoComplete( $term, $limit = 50 )
{
// build the query criteria
$countryCriteria = new CDbCriteria();
$countryCriteria->condition = "Country LIKE '$term%'";
$countryCriteria->order = "Country ASC";
$countryCriteria->limit = $limit;
// get the possible options
$countries = Country::model()->findAll( $countryCriteria );
foreach( $countries as $country )
{
$returnVal[] = array('label'=>$country->Country,'id'=>$country->CountryId);
}
// output as json for the autocomplete to render
echo CJSON::encode($returnVal);
}
Sorry, that should be $criteria->select = “blah” rather than in the () … I went too fast
If you’re just using the name property though, you should just ignore the select and if you want to add the code to the string, do so when you build the output array.
$term is posted by the CJuiAutoComplete widget and is the string that you typed in the box. In the example I posted, we’re using action parameter binding to require the term and pull it in from the $_GET array as part of the action method definition. Make sense?