Hi,
How i can send custom params for CJuiAutoCompelete.
I have 2 selects (selCategory, selCompany), i need send the values of these two selects on URL.
How i can do it?
Hi,
How i can send custom params for CJuiAutoCompelete.
I have 2 selects (selCategory, selCompany), i need send the values of these two selects on URL.
How i can do it?
hey!
I’m trying the same…
this can be a starting point
in the view
<?php
echo CHtml::dropDownList('dr',null,array('se', 'sel2', 'Item3'));
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1',
'options'=>array(
'search'=>"js:function(){alert('teste');
$('#test1').autocomplete({
source : 'http://localhost/kmcms/site/autocomplete?newparam=' + $('#dr :selected').text()
});
}"
),
));
?>
in the site controller
public function actionAutoComplete(){
$newparam = CHttpRequest::getParam('newparam',null);
//...do the rest
}
regards!
Hi,
I have solved the problem:
In the VIEW:
<script type="text/javascript">
function getProductListSource(request, response)
{
console.log("Buscando por: " + request.term);
var productListURL = '<?php echo $this->createUrl('auctions/getProductList'); ?>';
$.ajax({
url: productListURL,
dataType: "json",
data: {
supplier: $("#AdminFormAuctionDetails_fornecedor_id").val(),
category: $("#AdminFormAuctionDetails_category_main").val(),
term: request.term
},
success: function( data ) {
response( $.map( data, function( item ) {
return {
id: item.id,
value: item.value
}
}));
}
});
}
function selectProductOnList(event, ui)
{
if (ui.item)
{
console.log("ID:" + ui.item.id + " - VALUE: " + ui.item.value);
}
}
</script>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'producttitle',
'value'=>'',
'source'=>'js: function(request, response) { getProductListSource(request, response); }',
'options'=>array(
'showAnim'=>'fold',
'minLength'=>'3',
'delay' => '700',
'height' => '12px',
'autocomplete' => 'off',
'select' => 'js: function( event, ui ) { selectProductOnList(event, ui); }',
),
'htmlOptions'=>array(
'style' => 'width: 300px;',
),
));
?>
In the action:
public function actionGetProductList()
{
$res = array();
$term = isset($_GET['term']) ? $_GET['term'] : null;
if (empty($_GET['term']) == false) {
$criteria = new CDbCriteria();
$criteria->condition = 'producttitle LIKE :producttitle OR id = :id';
$criteria->params = array(':producttitle' => "%$term%", ':id' => (int)$term);
$criteria->offset = 0;
$criteria->limit = 10;
$productList = Product::model()->findAll($criteria);
foreach($productList as $product)
{
$res[] = array('id' => $product->id, 'value' => $product->id . ' - ' . $product->producttitle);
}
}
echo CJSON::encode($res);
Yii::app()->end();
}
good!
thanks for sharing!
regards!
I have updated the code. I forgot put the SELECT function. Only to show how to get selected item.