Yii CJuiAutoComplete小部件:空响应消息的事件

时间:2014-02-28 11:22:15

标签: yii autocomplete widget response is-empty

如果响应中不包含有关城市的数据,我想查看输出消息。此外,当我得到空响应时,我想在textfield中更改文本的CSS。

我有:

查看:

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'name'=>'city_id',
        'value'=>'',
        'source'=>CController::createUrl('/PromouterCity/autoComplete'),
        'options'=>array(           
            'showAnim'=>'fold',         
            'minLength'=>'0',
            'select'=>'js:function( event, ui ) {
                $("#city_id").val( ui.item.name );
                $("#selectedvalue").val( ui.item.id);
                return false;
             }',

        ),
        'placeholder' => "Search...",
        ),
));

控制器:

public function actionAutoComplete(){
$match=$_GET['term'];
    if(!empty($match)){
    $match = addcslashes($match, '%_'); 
    $q = new CDbCriteria( array(
    'condition' => "name LIKE :match", 
    'params'    => array(':match' => "$match%")
    ));
    $query = City::model()->findAll($q);
    }else{
        $query=array(
          '0'=>array(
            'id'=>'1',
            'name'=>'London',
          )
        );          
    }
    $list = array();        
    foreach($query as $q){
        $data['label']=$q['name'];
        $data['id']= $q['id'];
        $data['name']= $q['name'];
        $list[]= $data;
        unset($data);
    }
    echo CJSON::encode($list);      
  Yii::app()->end();    
}

1 个答案:

答案 0 :(得分:1)

决定:

'response'=> 'js:function( event, ui ) {
   if (ui.content.length === 0) {                   
     $("#empty-message").text("your message");
   } else {                         
     $("#empty-message").empty();
   }                
}',