Hello ppl, once again i have an ajax issue.
I have a view which has an ajaxLink view/_form.php
....
<div class="row">
<?php echo $form->labelEx($person,'jid'); ?>
<div id="job">
<?php echo $form->dropDownList($person,'jid',CHtml::listData(Job::model()->findAll(),'jid','jdescr'),array('prompt'=>'Select')); ?>
<?php echo CHtml::ajaxLink("test",$this->createUrl('/job/addnew'),array('onclick'=>'$("#jobDialog").dialog("open")','update'=>'#job'),array('id'=>'showJobDialog')); ?>
</div><!--//'success'=>'function(data) { $(data).appendTo("#job"); }'-->
<?php echo $form->error($person,'jid'); ?>
</div>
....
the result of this link is this actionAddnew in JobController.php
...
public function actionAddnew() {
$model=new Job;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Job']))
{
$model->attributes=$_POST['Job'];
if($model->save()) {
//Here where i want the CJuiDialog to close and create a dropdownlist to the main form
}
}
if(!isset($_GET['render'])) {
$this->renderPartial('createDialog',array(
'model'=>$model,
),false,true);
}
}
...
Please notice the comment in if($model->save()) .
Now the view/createDialog.php where the CJuiDialog initiallizes
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'jobDialog',
'options'=>array(
'title'=>Yii::t('job','Create Job'),
'autoOpen'=>'true',
'modal'=>'true',
),
));?>
<?php
echo $this->renderPartial('_formDialog', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
Which rendersPartial view/_formDialog.php which is this.
<div class="wide form" id="jobDialogForm">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'job-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'jid'); ?>
<?php echo $form->textField($model,'jid',array('size'=>60,'maxlength'=>90)); ?>
<?php echo $form->error($model,'jid'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'jdescr'); ?>
<?php echo $form->textField($model,'jdescr',array('size'=>60,'maxlength'=>180)); ?>
<?php echo $form->error($model,'jdescr'); ?>
</div>
<div class="row buttons">
<?php //echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');
echo CHtml::ajaxSubmitButton(Yii::t('jib','Create Job'),CHtml::normalizeUrl(array('job/addnew','render'=>false)),array('update'=>'#job'),array(
)); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
I want when I press the create on the CJuiDialog to be able to save the model (if passed the validation) and update or replace the dropdownlist in the main _form so it contains the new entry.
Any help welcom.