I have a question
How these fields(select2) are validated?
I get an error because it is required and does not send any value
This is my form
<?php
echo CHtml::hiddenField('Id_Usuario','', array('class' => ''));
$this->widget('ext.select2.ESelect2',array(
'selector' => '#Id_Usuario',
'model'=>$model,
'attribute' => 'Id_Usuario',
// 'value'=>$model->Id_Usuario,
'options' => array(
'allowClear'=>true,
'placeholder'=>'Selecione el Demandante',
'width' => '220px',
'ajax'=>array(
'url'=>$this->createUrl('ListarDemandantes'),
'dataType' => 'json',
// 'type'=>'GET',
'quietMillis'=> 100,
'data' => 'js: function(text,page) {
return {
q: text,
page_limit: 10,
page: page,
};
}',
'results'=>'js:function(data,page) { var more = (page * 10) < data.total; return {results: data, more:more };
}',
'formatSelection'=>'js: function(data) {
return data.title;
}',
'initSelection'=>'js: function(element, callback) {
var elementText = $(element).data("init-text");
callback({"title":elementText});
}',
),
),
));
?>
My controller
public function actionListarDemandantes(){
$lista =Usuarios::model()->findAll('Nombres like :term or Apellidos like :term' ,array(':term'=>"%".$_GET['q']."%"));
$reusultados = array();
foreach ($lista as $model){
$reusultados[] = array(
'id'=>$model->Id_Usuario,
'text'=>$model->Nombres.' '.$model->Apellidos,
);
}
echo CJSON::encode($reusultados);
}
Thank you very much