yii
(jammi )
April 25, 2011, 8:20am
1
Hi,
I’m using CAutocomlete very successfully but have a problem with a second parameter
<?php
$this->widget('CAutoComplete',
array(
'name' => 's',
'value' => $sValue,
'url' => array('translation/autoCompleteLookup'),
'extraParams' => array('l' => $dCl),
'minChars' => 2,
'delay' => 10,
'matchCase' => false,
'htmlOptions'=>array('size'=>'40', 'id' => 'searchfield' ),
'methodChain'=> ".result(function(event,item){\$(this).parents(form).submit();})",
));
?>
I have a dropdown next to my input field, but i don’t know how to get the selected value to autocomplete?!
<select name="l">
<option value="1">BMW</option>
<option value="2">AUDI</option>
<option value="3">SEAT</option>
</select>
If the user selected an AUDI, than extraParams should get 2 as a value.
Please help me!
thank you!
yii:
Hi,
I’m using CAutocomlete very successfully but have a problem with a second parameter
<?php
$this->widget('CAutoComplete',
array(
'name' => 's',
'value' => $sValue,
'url' => array('translation/autoCompleteLookup'),
'extraParams' => array('l' => $dCl),
'minChars' => 2,
'delay' => 10,
'matchCase' => false,
'htmlOptions'=>array('size'=>'40', 'id' => 'searchfield' ),
'methodChain'=> ".result(function(event,item){\$(this).parents(form).submit();})",
));
?>
I have a dropdown next to my input field, but i don’t know how to get the selected value to autocomplete?!
<select name="l">
<option value="1">BMW</option>
<option value="2">AUDI</option>
<option value="3">SEAT</option>
</select>
If the user selected an AUDI, than extraParams should get 2 as a value.
Please help me!
thank you!
hey!
try the following in your view
$this->widget('CAutoComplete',
array(
...
//insert the ID of your select
'methodChain'=>".result(function(event,item){\$(\"#1\").val(item[1]); })",
));
in the controller
public function actionAutoCompleteLookup()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
{
....
$criteria = new CDbCriteria;
$criteria->condition = ...;
$criteria->params = ...;
$resultArray = MyModel::model()->findAll($criteria);
$returnVal = '';
foreach($resultArray as $resultItem)
{
//this is the code to return name and id
$returnVal .= $resultItem->getAttribute('name').'|'
.$resultItem->getAttribute('id')."\n";
}
echo $returnVal;
}
}
hope this can help you, it works fine for me
regards!!!
yii
(jammi )
April 25, 2011, 2:31pm
3
thank you for your reply, but it doesn’t work.
'methodChain'=>".result(function(event,item){\$(\"#l\").val(item[1]); })", // NEW
'methodChain'=> ".result(function(event,item){\$(this).parents(form).submit();})", // OLD
l for categorie should be give as an extra Parameter
oh, sorry, i misunderstood what you wanted to do…the code i posted is not suitable for your situation…i thought you were trying to set the value from autocomplete to the select option input
accordling to the docs, I’d try to get the l value in the controller as
$l = CHttpRequest::getParam('l', null);
regards
yii
(jammi )
April 25, 2011, 2:58pm
5
scoob.junior:
oh, sorry, i misunderstood what you wanted to do…the code i posted is not suitable for your situation…i thought you were trying to set the value from autocomplete to the select option input
accordling to the docs, I’d try to get the l value in the controller as
$l = CHttpRequest::getParam('l', null);
regards
my english is very terrible
is it possible to load the selected value from the dropdown list to
'extraParams' => // HERE JQUeRY?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?
please, see this topic answered by Qiang:
http://www.yiiframework.com/forum/index.php?/topic/371-extraparams-in-cautocomplete/
i haven’t tested it, but it seems that extraParams also accepts a “js:function(){ }”
yii:
thanks for reply.
But what does he mean?
??
think that you can do something like
"js:function(){ //code to return $('#div_to_get_value_dinamic').val(); }"