Hello ppl,
I will try to be give as may information as possible.
I have a model person where in _form.php view i have this code:
<div id="doy">
<?php echo $form->dropDownList($person,'doyid',CHtml::listData(Doy::model()->findAll(),'doyid','doyname'),array('prompt'=>'Select')); ?>
<?php echo CHtml::ajaxLink("Add new Doy.",$this->createUrl('/doy/addnew'),array('replace'=>'#doy'));?>
</div>
So there is a dropdownlist feeded with data from an other model Doy and a ajaxLink in case you can not find what you want and be able to add it with the function of the models (doy) addnew action which is the following:
public function actionAddnew()
{
$model=new Doy;
$this->performAjaxValidation($model); // I want to perform validation
if(isset($_POST['Doy'])){
$model->attributes=$_POST['Doy'];
if($model->save()){
echo "test";
}
} else {
$this->renderPartial('_form_1',array('doy'=>$model),false,true);
}
}
For the moment keep in mind the echo "test";
line.
The very first time when the actionAddnew will be called the _form_1 will be rendered.Here is _form_1.php view:
<div class="wide form" >
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'doy-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo CHtml::errorSummary($doy); ?>
<div class="row">
<?php echo $form->labelEx($doy,'doyid'); ?>
<?php echo $form->textField($doy,'doyid',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($doy,'doyid'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($doy,'doyname'); ?>
<?php echo $form->textField($doy,'doyname',array('size'=>60,'maxlength'=>90)); ?>
<?php echo $form->error($doy,'doyname'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton(Yii::t('forms','Create'),CHtml::normalizeUrl(array('doy/addnew'),array('replace'=>'#doy'))); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Ok…where is the problem. When i visit the _pform there is the dropdown list (codesnippet1) when i clik on the ajaxLink there the form renders proper replacing the dropdownlist. I insert values it validate them and i press the create of the _form_1 which is the ajaxSubmitButton. The values are submiting but the form is not replaced as it should from the echo "test";
Of course i dont want only test to be rendered but in fact i want a new dropdownlist with the values submitted previously to be the selected. Please help because i am new to ajax and yii.
What is the problem? If you want more information please inform.