cjuiautocomplete ajax,autocomplete - Yii CJuiAutoComplete data from Ajax request - Stack Overflow

I have a task form for an application I am building which allows me to specify what contact it is assigned to. I had set up a dependent dropdown in Yii with the following code:

echo $form->dropDownList($model,'associationType',

array('none'=>'None','contact'=>'Contact','sale'=>'Sale','account'=>'Account',

'project'=>'Project','case'=>'Case'),

array(

'ajax' => array(

'type'=>'POST', //request type

'url'=>CController::createUrl('tasks/parseType'), //url to call.

//Style: CController::createUrl('currentController/methodToCall')

'update'=>'#auto_complete', //selector to update

)

));

What I'm trying to do is use the CJuiAutoComplete widget with the dropDown specifying which array to grab. So the drop down is selected to contacts, it should get a list of contacts etc.

Here is what I have for the CJui widget

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

'name'=>'auto_select',

'source' => $names,

'options'=>array(

'minLength'=>'2',

'select'=>'js:function( event, ui ) {

$("#'.CHtml::activeId($model,'associationId').'").val(ui.item.id);

return false;

}',

),

));

The variable $names is just a placeholder for now, but in my controller method I pass it a JSON encoded array with id and name. Controller code:

public function actionParseType() {

//if(isset($_POST['TaskChild']['associationType'])){

//$type=$_POST['TaskChild']['associationType'];

$type='sale';

$sql = 'SELECT id, name FROM x2_'.$type.'s';

$cmd = Yii::app()->db->createCommand($sql);

$res = $cmd->queryAll();

echo CJSON::encode($res);

//}

}

Right now I'm forcing it to use "Sale" but I don't get anything when I call the method, and was wondering how I might go about fixing this. I'm still a little new to Yii so I've been mostly reading wiki/forum posts on how these kinds of thing are done. Any help is greatly appreciated, thanks!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值