Happy New Year all!
Sorry to be a thicko - im back to a Yii project, and I’ve got the auto / suggest working, e.g. I type "tea " and “Teacher” appears, but when I submit, it says the field is empty, and looking with FireBug the field value doesnt have “Teacher” in it…
Do I need a hidden field with a specific ID/Name?
<div class="row">
<?php echo $form->labelEx($model,'client_2_occupation'); ?> [Auto from DB]
<?php //echo $form->textField($model,'client_2_occupation',array('class'=>'typeahead-occupation','size'=>60,'maxlength'=>128)); ?>
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
//'model'=>$model,
'id'=>'client_2_occupation',
'name'=>'client_2_occupation',
'value'=>"Type keyword in here...",
'source' => CController::createUrl('site/suggest'),
'options'=>array(
'delay'=>300,
'minLength'=>2,
),
)); ?>
<?php echo $form->error($model,'client_2_occupation'); ?>
</div>
/**
* Enables suggestive form fields.
*/
public function actionSuggest()
{
if (Yii::app()->request->isAjaxRequest && isset($_GET['term'])&&($keyword=trim($_GET['term']))!=='')
{
$models=FormFields::model()->findAll(array(
'condition'=>'value_int LIKE :keyword OR value_char LIKE :keyword',
'order'=>'value_char',
'limit'=>5,
'params'=>array(':keyword'=>"$keyword%")
));
$suggest=array();
foreach($models as $model) {
$suggest[] = array(
'label'=>$model->value_char,
'value'=>$model->value_char
);
}
echo CJSON::encode($suggest);
}
}