Question

If the response does not contain data about the city, I want to see the output message. Also i want to change css of text in textfield when I get an empty response.

I have:

View:

$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...",
        ),
));

Controller:

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();    
}
Was it helpful?

Solution

Decision:

'response'=> 'js:function( event, ui ) {
   if (ui.content.length === 0) {                   
     $("#empty-message").text("your message");
   } else {                         
     $("#empty-message").empty();
   }                
}',
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top