In the application have an address model contain name,sex, address fields. Now trying to create the address on pop box (using CJuiDialog box). The pop up box and form loaded correctly. But when click to the create button without input data, the popup box disapprear. Then next time open the popup box, it shows validation errors (based on previous attempt). How it solve?
Controller
public function actionCreate()
{
$model=new Address;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Address']))
{
$model->attributes=$_POST['Address'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
create.php
<h1>Create Address</h1>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>false,
),
));
?>
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
// the link that may open the dialog
echo CHtml::link('open dialog', '#', array(
'onclick'=>'$("#mydialog").dialog("open"); return false;',
));
?>
_form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'address-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,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>22,'maxlength'=>22)); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'sex'); ?>
<?php echo $form->dropdownlist($model,'sex',array("1" => "Male", "2" => "Female"),array('style'=>'width: 125px','empty'=>array('Select'=>'Select')));?>
<?php echo $form->error($model,'sex'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address',array('size'=>22,'maxlength'=>22)); ?>
<?php echo $form->error($model,'address'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Thanks.