Help with AJAX and Partial Render

All I’m creating an application for some calculations. I want it to be dynamic, so I want to use AJAX to render different divs in the form. I’m using the widget ESelect2 for my dropdowns since they look pretty nice.

My form actually looks like this:


<?php

/* @var $this FsDetailController */

/* @var $model FsDetail */

/* @var $form CActiveForm */

?>


<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'fs-detail-form',

    'enableClientValidation'=>true,

	'htmlOptions'=>array('enctype'=>'multipart/form-data'),

	'clientOptions'=>array('validateOnSubmit'=>true),

	// Please note: When you enable ajax validation, make sure the corresponding

	// controller action is handling ajax validation correctly.

	// There is a call to performAjaxValidation() commented in generated controller code.

	// See class documentation of CActiveForm for details on this.

	'enableAjaxValidation'=> false,

)); ?>


	<p class="note"><?php echo Translation::model()->translate(Yii::app()->language,'Fields with',null); ?> <span class="required">*</span> <?php echo Translation::model()->translate(Yii::app()->language,'are required',null); ?>.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'fs_id'); ?>

		<?php $model->fs_id = $_GET['id']; echo $form->textField($model,'fs_id',array('size'=>15,'maxlength'=>15,'disabled'=>true)); ?>

		<?php echo $form->error($model,'fs_id'); ?>

	</div>

    <table>

	<tr>

    <td width=5px>

    <div class="row">

		<?php echo $form->labelEx($model,'fs_structure_id'); ?>

        <?php

        $fsmodel = FinancialStatement::model()->findbyPk($_GET['id']);

        $fsstructuremodel = FsStructure::model()->findAllbyAttributes(array('fs_category_id' => $fsmodel->fs_category_id)/*,array('order'=>'fs_structure_name ASC')*/);

		

        $listData_fs_structure = CHtml::listData($fsstructuremodel,'fs_structure_id' ,'fs_structure_name');

        $t_listData_fs_structure = array();

        foreach ($listData_fs_structure as $key => $item)

        {

            $t_listData_fs_structure[$key]=Translation::model()->translate(Yii::app()->language, $item, null);

        }

        

        $this->widget('ext.select2.ESelect2',array(

  			'model'=>$model,

			'attribute'=>'fs_structure_id',

			'data'=>$t_listData_fs_structure,

			'options'=>array(

				'placeholder'=>Translation::model()->translate(Yii::app()->language,'Select',null),

                'allowClear' => true,

			),

			'htmlOptions'=>array(

				'style'=>'width:200px',

				//'multiple'=>'multiple',

			),

  			

		)); 

		

		?>

		<?php echo $form->error($model,'fs_structure_id'); ?>

	</div>

    </td>

    <td>

	<div class="row">

		<?php echo $form->labelEx($model,'fs_detail_calculation_id'); ?>

		<?php

        $listData_fs_calculation = CHtml::listData(FsDetailCalculation::model()->findAll(),'fs_detail_calculation_id','fs_detail_calculation_name');

        $t_listData_fs_calculation = array();

        foreach ($listData_fs_calculation as $key => $item)

        {

            $t_listData_fs_calculation[$key]=Translation::model()->translate(Yii::app()->language, $item, null);

        }

        

		$this->widget('ext.select2.ESelect2',array(

  			'model'=>$model,

			'attribute'=>'fs_detail_calculation_id',

			'data'=>$t_listData_fs_calculation,

            'options'=>array(

				'placeholder'=>Translation::model()->translate(Yii::app()->language,'Select',null),

                'allowClear' => true,

                

			),

			'htmlOptions'=>array(

				'style'=>'width:200px',

				//'multiple'=>'multiple',

                'ajax' => array (

                       'type'=>'POST',

                       //'url'=>CController::createUrl ('calculationamount'), 

                       //'update'=>'#fs_detail_amount',

                       'dataType'=>'html',

                       'url'=>CController::createUrl ('ajaxRefresh'), 

                       'success'=>"function(data){

                               $('#fs_detail_amount').html(data.fs_detail_amount);

                               $('#calculation_type').html(data.calculation_type);

                            }"

                    ),

			),

  			

		)); 

		

		?>

		<?php echo $form->error($model,'fs_detail_calculation_id'); ?>

	</div>

    </td>

    <td>

    <div id="fs_detail_amount"></div>

    </td>

    <td>

    <div id="calculation_type"></div>

    </td>

    </tr>

    </table>

	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->

_formAmount.php


<?php

$form=$this->beginWidget('CActiveForm', array(

	                'id'=>'fs-detail-form',

                    'enableClientValidation'=>true,

	                'htmlOptions'=>array('enctype'=>'multipart/form-data'),

	                'clientOptions'=>array('validateOnSubmit'=>true),

	                // Please note: When you enable ajax validation, make sure the corresponding

	                // controller action is handling ajax validation correctly.

	                // There is a call to performAjaxValidation() commented in generated controller code.

	                // See class documentation of CActiveForm for details on this.

	                'enableAjaxValidation'=> false,

                ));

 ?>

 <?php

 if ($value != 1){

                //echo "<td >";

                echo $form->labelEx($model,'fs_detail_amount');

                echo $form->textField($model, 'fs_detail_amount', array('disabled'=>true));

                echo $form->error($model,'fs_detail_amount');

                //echo "</td>";

}else if ($value == 1){

                echo $form->labelEx($model,'fs_detail_amount'); 

                $this->widget('CMaskedTextField', array(

                        'model'=>$model,

                        //'value'=>'',

                        'attribute'=>'fs_detail_amount',

                        'mask'=>'9,999.00',

                        

                    ));

                echo $form->error($model,'fs_detail_amount');

 }

 ?>

<?php                $this->endWidget();?>



and the Actions from my controllers are:


public function actionCalculationAmount ()

    {

    $model = New FsDetail;

    //$model = array(['FsDetail']);

    $value = $_POST['FsDetail']['fs_detail_calculation_id'];

                $this->renderPartial('_formAmount',array(

					        'model'=>$model,'value'=>$value,

                            ),

                false,true);

    }

    

    public function actionAjaxRefresh ()

    {

    $model = New FsDetail;

    $value = $_POST['FsDetail']['fs_detail_calculation_id'];

                $dfs_detail_amount=$this->renderPartial('_formAmount', array('model'=>$model,'value'=>$value), false, true);

                $calculation_type=$this->renderPartial('_formCalcType', array('model'=>$model), false, true);


    }

My data entry should look like this

| Structure | Calculation Category | Detail Amount (Dinamic based on Category) | Calculation Type (Dinamic Dropdown based on Category) |

I have only been able to make dinamic the detail amount (enable or disable) based if the category is manual entry or requires another calculation.

Please let me know everyone if you know how to solve this issue.