ESelect2
ESelect2 copied to clipboard
Select2 not storing ID
Hi All, I am using select2 extension. But when trying to save (create) record even though I select from the list, it gives the error "Teilnehmer cannot be blank."
View: $this->widget('ext.select2.ESelect2', array( 'model'=>$model, 'attribute' => 'cTeilnehmerID', 'data'=>CHtml::listData(Teilnehmer::model()->findAll(),'cTeilnehmerID','fullName'), 'options'=>array( 'width'=>'300px', 'placeholder'=>' -- please select -- ', 'sourceUrl'=>array('buchung/autoComplete'), ) )); Controller: public function actionAutoComplete() {
$criteria = new CDbCriteria;
$criteria->select = array('cTeilnehmerID','cVorname','cNachname');
$criteria->addSearchCondition('cVorname', strtoupper( $_GET['term']) ) ;
$criteria->addSearchCondition('cNachname', strtoupper ( $_GET['term']), true, 'or');
$criteria->addSearchCondition('CONCAT(cVorname," ",cNachname)', strtoupper ( $_GET['term']), true, 'or');
$criteria->limit = 15;
$data = Teilnehmer::model()->findAll($criteria);
$res = array();
foreach ($data as $item) {
$res[] = array(
'id' => $item->cTeilnehmerID,
'value' => $item->fullName,
'label' => $item->fullName,
);
}
echo CJSON::encode($res);
}