I am trying to get CAutoComplete to work with Key => Value Pairs so that the field autocompletes the key, but upon form submission the values are returned. As an example:
<?php echo $form->labelEx($model,'fruit_id'); ?>
<?php
// Get the fruits (id, name) data
$fruits = fruits::model()->findAll();
$fruit_codes = array();
foreach($fruits as $fruit)
{
$fruit_codes[$fruit->name] = $fruit->id;
}
$this->widget('CAutoComplete', array(
'model'=>$model,
'attribute'=>'fruit_id',
'data'=>$fruit_codes,
'multiple'=>false,
'htmlOptions'=>array('size'=>25),
));
?>
<?php echo $form->error($model,'fruit_id'); ?>
Is there a way to do this with the CAutoComplete widget? If not, is there an alternative way in Yii of autocompleting keys and returning values withing a form?