So, I tried the both
I have a problem with that one:
I replace that from the tutorial
<?php echo $form->dropDownList([b]$person,'jid'[/b],CHtml::listData(Job::model()->findAll(),'jid','jdescr'),array('prompt'=>'Select')); ?>
by
<?php echo $form->dropDownList([b]$model,'Customer_id'[/b],CHtml::listData(Customer::model()->findAll(),'id','CustomerName'),array('prompt'=>'Select')); ?>
because I had an error and I did not understand what does It means.
When I clic on create button, the Ajax pop-up appear but when I clic on "Create Customer" the dialogBox close and :
Help me please,
Here my files:
_form (from the model Transport)
<div class="row">
.....
<?php echo $form->labelEx($model,'id'); ?>
<div id="customer">
<?php echo $form->dropDownList($model,'Customer_id',CHtml::listData(Customer::model()->findAll(),'id','CustomerName'),array('prompt'=>'Select')); ?>
<?php echo CHtml::ajaxLink(Yii::t('customer','Create Job'),$this->createUrl('Customer/addnew'),array(
'onclick'=>'$("#customerDialog").dialog("open"); return false;',
'update'=>'#customerDialog'
),array('id'=>'showcustomerDialog'));?>
<div id="customerDialog"></div>
</div>
.....
</div>
CustomerController.php
public function actionAddnew()
{
$model=new Customer;
// Ajax Validation enabled
$this->performAjaxValidation($model);
// Flag to know if we will render the form or try to add
// new jon.
$flag=true;
if(isset($_POST['Customer']))
{ $flag=false;
$model->attributes=$_POST['Customer'];
if($model->save()) {
//Return an <option> and select it
echo CHtml::tag('option',
array (
'value'=>$model->id,
'selected'=>true
),
CHtml::encode($model->CustomerName),true);
}
}
if($flag) {
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('createDialog',array('model'=>$model,),false,true);
}
}
My createDialog.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'customerDialog',
'options'=>array(
'title'=>Yii::t('customer','Create customer'),
'autoOpen'=>true,
'modal'=>'true',
'width'=>'auto',
'height'=>'auto',
),
));
echo $this->renderPartial('_formDialog', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
_formDialog
<div class="form" id="customerDialogForm">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-form',
'enableAjaxValidation'=>true,
));
//I have enableAjaxValidation set to true so i can validate on the fly the
?>
<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,'id'); ?>
<?php echo $form->textField($model,'id',array('size'=>60,'maxlength'=>90)); ?>
<?php echo $form->error($model,'id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'CustomerName'); ?>
<?php echo $form->textField($model,'CustomerName',array('size'=>60,'maxlength'=>180)); ?>
<?php echo $form->error($model,'CustomerName'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton(Yii::t('Customer','Create Customer'),CHtml::normalizeUrl(array('Customer/addnew','render'=>false)),array('success'=>'js: function(data) {
$("#model").append(data);
$("#customerDialog").dialog("close");
}'),array('id'=>'closecustomerDialog')); ?>
</div>
<?php $this->endWidget(); ?>
</div>
Thank you, (I’m a beginner)