do somebody have any example on how to use CjuiAutoComplete with sourceUrl?
i read it from the documentation that it could get ajax response by using sourceUrl.
but still no demo though. thks
do somebody have any example on how to use CjuiAutoComplete with sourceUrl?
i read it from the documentation that it could get ajax response by using sourceUrl.
but still no demo though. thks
I am working on figuring this out, and I found this
http://www.yiiplayground.cubedwater.com/index.php?r=UiModule/jui/ziiAutocomplete
You can do like this
$arr = array();
foreach($models as $model)
{
$arr[] = array(
'label'=>$model->some_attr, // label for dropdown list
'value'=>$model->some_attr, // value for input field
'id'=>$model->id, // return value from autocomplete
);
}
echo CJSON::encode($arr);
Edit: ‘label’ is useful for presenting more details in the dropdown list eg. ‘name (pk)’.
/Tommy
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'adm_area',
'sourceUrl'=>array('ac_admarea'),
'cssFile'=>false,
'htmlOptions'=>array('placeholder'=>'Any'),
'scriptUrl'=>'/protected/controllers/js',
));
?>
I’am trying with CJuiAutoComplete but the value is not submitted with the form.
My example:
```
$form=$this->beginWidget('CActiveForm', array(
'id'=>'personas-buscapersona-form',
'enableAjaxValidation'=>false,));
echo $form->hiddenField($model, 'idperson');
echo $form->labelEx($model,'nombre');
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
// 'name' => 'Daytrip[nombre]',
'name' => 'nombre',
'sourceUrl' => array('reservatandem/SuggestPerson'),
'value' => $model->nombre,
'options' => array(
'showAnim' => 'fold',
//remove if you dont need to store the id, like i do...
'select' => 'js:function(event, ui){ jQuery("#Daytrip_idperson").val(ui.item["idperson"]); }'
),
'htmlOptions' => array(
'style'=>'height: 20px; width: 300px;',
//'style' => 'height:20px; w'
),
));
echo CHtml::submitButton('Select');
$this->endWidget();
```
in the controller
public function actionSeleccionaCliente()
{
$model=new Personas; //para seleccionar el cliente
if(isset($_POST['Personas']))
{
$model->attributes=$_POST['Personas'];
$this->idperson=$model->idperson;
if($model->validate())
{
$this->_model = $model;
$this->redirect(array('reserva02','id'=>$model->idperson));
}
}
$iddropzone=Yii::app()->user->dropzone;
$idroll=Yii::app()->user->idroll;
$dropzone = Dropzones::model()->findByPk($iddropzone);
$this->render('buscapersona',array(
'model'=>$model,
'namezone'=>$dropzone->namezone,
));
}
It works!
Thank you for this little but precious bit of code.
Dear Friends,
I still did not manage to understand well the field source.
Does the line 12 of the script down indicate exatamente what? a path to directory? or archive?
09 $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
10 'name'=>'test1',
11 'value'=>'test21',
12 'source'=>$this->createUrl('jui/autocompleteTest'),
13 // additional javascript options for the autocomplete plugin
14 'options'=>array(
15 'showAnim'=>'fold',
16 ),
17 ));
congratulations
In this case a URL. See the explanation here.
/Tommy