Hi,
i want , i choose food’s name with autocomplete and selected food’s name shown in autocomplete and selected food’s calory shown in other textfield and selected food’s id record in my table with activerecord…
i success select food with autocomplete and fill the other textfield food’s calory but i dont record this food id in my table.
i have a table, Yemekler
This table’s fields ; id yemekAdi niteligi kalori
when i click the submit button, i want to selected food’s id record the in my database. But form send food’s name
for record. due to the value not integer, record not success.
Thanks for help.
my codes at below
menu.php view
<div class="row">
<?php echo $form->labelEx($model,'yemek1'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$model->yemek1,
'name'=>'Menu_yemek1',
'source'=>$this->createUrl('kayit/autocompleteTest'),
'options'=>array(
'delay'=>300,
'minLength'=>1,
'showAnim'=>'fold',
'focus'=>'js:function( event, ui ) {
$( "#Menu_yemek1" ).val( ui.item.label );
return false;
}',
'select'=>"js:function(event, ui) {
$('#Menu_yemek1').val(ui.item.label);
$('#kalori1').val(ui.item.kalori1);
return false;
}",
),
'htmlOptions'=>array(
'size'=>'40'
),
));
?>
<?php echo $form->error($model,'yemek1'); ?>
</div>
<div class="row">
<?php echo CHtml::textField('kalori1','',array('id'=>'kalori1','disabled' => true)); ?>
</div>
KayitController.php controller
public function actionAutocompleteTest() {
$res =array();
if (isset($_GET['term'])) {
$sql = 'SELECT yemekAdi as label, id as value, kalori as kalori1 FROM yemekler ';
$sql = $sql . ' WHERE niteligi=1 and yemekAdi LIKE :label'; // Must be at least 1
$command =Yii::app()->db->createCommand($sql);
$command->bindValue(":label", '%'.$_GET['term'].'%', PDO::PARAM_STR);
echo json_encode ( $command->queryAll () );
}
}