I´m trying to make an form with 2 dropdownlist.
The firts dropdownlist, has all formats and the second dropdownlist has the concept of each format.
Estoy tratando de crear dos listas. Una tiene todos los formatos y la otra tiene todos los conceptos de cada formato. La idea es que al seleccionar el formato, la otra lista se cargue con sus conceptos
This is my view code / Este es mi código de la vista
<script>
$(document).ready(function(){
if ('<?php echo $model->id_cuenta; ?>' != '' ) {
$('#ExogenaColconCuenta_id_cuenta').prepend('<option value="<?php echo $model->id_cuenta ?>"><?php echo $model->idCuenta->cuenta." - ".$model->idCuenta->nombre?></option>');
}
});
</script>
<div class="form">
<?php
/** @var ExogenaColconCuentaController $this */
/** @var ExogenaColconCuenta $model */
/** @var AweActiveForm $form */
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
'id' => 'exogena-colcon-cuenta-form',
'type'=>'horizontal',
'enableAjaxValidation' => true,
'enableClientValidation'=> true,
)); ?>
<p class="note">
<?php echo Yii::t('AweCrud.app', 'Fields with') ?> <span class="required">*</span>
<?php echo Yii::t('AweCrud.app', 'are required') ?>. </p>
<?php echo $form->errorSummary($model) ?>
<?php echo $form->dropDownListGroup( $model, 'id_formato', array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(ExogenaFormato::model()->findAll(), 'id_formato', ExogenaFormato::representingColumn()),
'htmlOptions' => array('empty'=>'Seleccionar'),
),
'ajax' => array(
'type' => 'POST',
'url' => Yii::app()->createURL('ExogenaColconCuenta/SelectConcepto'),
'update' => '#ExogenaColconCuenta_id_concepto',
),
)); ?>
<?php echo $form->dropDownListGroup( $model, 'id_concepto', array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
)); ?>
<?php /*echo $form->dropDownListGroup( $model, 'id_concepto', array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(ExogenaConcepto::model()->findAll(), 'id', ExogenaConcepto::representingColumn()),
'htmlOptions' => array('empty'=>'Seleccionar'),
)
)
); */?>
<?php echo $form->dropDownListGroup( $model, 'id_columna', array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(ExogenaColumna::model()->findAll(), 'id', ExogenaColumna::representingColumn()),
'htmlOptions' => array('empty'=>'Seleccionar'),
)
)
); ?>
<?php
echo $form->select2Group(
$model,
'id_cuenta',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
'value'=> "a",
),
'widgetOptions' => array(
'options'=> array(
'ajax'=>array(
'url'=> $this->createUrl('cuentaContable/CuentaListAC'),
'dataType'=>'json',
'delay'=> 250,
'data'=> 'js:function(params) {
return {
term: params.term, // search term
page: params.page
};
}',
'processResults'=> 'js:function (data, page) {
return {
results: data.items
};
}',
'cache' => true,
),
'minimumInputLength'=>2,
'language'=> 'es',
'escapeMarkup'=>'js:function (markup) { return markup; }',
'templateResult'=>'js:function (item) {
return item.text;
}',
'templateSelection' =>'js:function (item) {
return item.text;
}',
),
'htmlOptions' => array(
),
)
)
);
?>
<?php echo $form->switchGroup($model, 'active') ?>
<?php echo $form->textAreaGroup($model,'notas',
array( 'wrapperHtmlOptions' => array( 'class' => 'col-sm-5',),'widgetOptions' => array('htmlOptions' => array('rows' => 5),)) ); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'context'=>'primary',
'label'=>$model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
//'buttonType'=>'submit',
'label'=> Yii::t('AweCrud.app', 'Cancel'),
'htmlOptions' => array('onclick' => 'javascript:history.go(-1)')
)); ?>
</div>
<?php $this->endWidget(); ?>
</div>
This is my controller code / este es el código del controlador
<?php
class ExogenaColconCuentaController extends AweController
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout = '//layouts/column1';
public $defaultAction = 'admin';
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view', array(
'model' => $this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new ExogenaColconCuenta;
$this->performAjaxValidation($model, 'exogena-colcon-cuenta-form');
if(isset($_POST['ExogenaColconCuenta']))
{
$model->attributes = $_POST['ExogenaColconCuenta'];
if($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create',array(
'model' => $model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$this->performAjaxValidation($model, 'exogena-colcon-cuenta-form');
if(isset($_POST['ExogenaColconCuenta']))
{
$model->attributes = $_POST['ExogenaColconCuenta'];
if($model->save()) {
$this->redirect(array('view','id' => $model->id));
}
}
$this->render('update',array(
'model' => $model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('ExogenaColconCuenta');
$this->render('index', array(
'dataProvider' => $dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin($export= 'grid')
{
$model = new ExogenaColconCuenta('search');
if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller
}
//$model->unsetAttributes(); // clear any default values
//if(isset($_GET['ExogenaColconCuenta']))
//$model->attributes = $_GET['ExogenaColconCuenta'];
if (isset($_GET['pageSize'])) {
Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
unset($_GET['pageSize']); // would interfere with pager and repetitive page size change
}
$this->render('admin', array(
'model' => $model,
'export' => $export,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id, $modelClass=__CLASS__)
{
$model = ExogenaColconCuenta::model()->findByPk($id);
if($model === null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model, $form=null)
{
if(isset($_POST['ajax']) && $_POST['ajax'] === 'exogena-colcon-cuenta-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
public function actionSelectConcepto(){
header( 'Access-Control-Allow-Origin: *' );
file_put_contents('/var/www/html/asw7/protected/runtime/log.txt',"Entra a selectConcept".PHP_EOL, FILE_APPEND);
$id_format = $_POST['ExogenaColconCuenta']['id_formato'];
$lista = ExogenaConcepto::model()->findAll('id_formato = :id_format', array(':id_format'=>$id_format));
$lista = CHtml::listData($lista, 'id', 'nombre');
foreach ($lista as $key => $value) {
echo CHtml::tag('option',array('value'=>$key), CHtml::encode($value), true);
}
}
}
Never calls to controller function in the action change / Nunca llama la función del controlador en el change del primer dropdown
Can you help me please? / Podrían ayudarme por favor?
PS: I already set the enableAjaxValidation to false and it doesn’t work
PD: Ya modifiqué el enableAjaxValidation a false y tampoco funcionó