Hello,
I am using a CJUIDialog for create Absence since a grid view.
I would like to use validation as usual _form.
My CJuiDialog :
my gridview :
the controller :
I think I have to pass the model with erroe trough CJSON, but how can I do ?
Nath
I am using a CJUIDialog for create Absence since a grid view.
I would like to use validation as usual _form.
My CJuiDialog :
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog 'id' => 'dialogAbsence', 'options' => array( 'title' => Yii::t('view', 'creerAbsenceDfc'), 'autoOpen' => false, 'modal' => true, 'width' => 700, 'height' => 440, ), )); ?> <div class="form"> <div class="divForForm"> <?php $formAbsence = $this->beginWidget('bootstrap.widgets.TbActiveForm', array( 'id' => 'dfc-form-absence', 'type' => 'horizontal', 'enableAjaxValidation' => false, 'enableClientValidation' => true, 'clientOptions' => array('validateOnSubmit' => true), )); ?> <?php echo $formAbsence->errorSummary($modelAbsence); ?> <div style="float:left;width:50%"> <div> <?php $modelAbsence->fk_planning_id = $modelPlanning->planning_id; echo $formAbsence->hiddenField($modelAbsence, 'fk_planning_id'); echo $formAbsence->hiddenField($modelAbsence, 'fk_mesure_id', array('id' => 'mesureId')); ?> </div> <div> <?php echo CHtml::label(Yii::t('model', 'fkCodeTypeAbsence'), 'fk_code_type_absence', array()); ?> <div> <?php echo $formAbsence->RadioButtonList($modelAbsence, 'fk_code_type_absence', $listAbsences, array('class' => 'ckTypeAbsence', 'tabindex' => 1,)); ?> </div> <?php //echo $formAbsence->error($formAbsence, 'fk_code_type_absence'); ?> </div> <div class="control-group" id="tfHeure" style="display:none"> <?php echo CHtml::label('heure', 'heure_debut', array()); ?> <div> <div class="input-prepend"> <?php echo $formAbsence->TextField($modelAbsence, 'heure_debut', array('class' => 'input-mesure', 'tabindex' => 2,)); ?> </div> </div> </div> <div class="control-group" id="ddlMotifAbsence" style="display:none"> <?php echo CHtml::label(Yii::t('model', 'fkCodeMotifAbsence'), 'fk_code_motif_absence'); ?> <div> <div class="input-prepend"> <?php echo $formAbsence->DropDownList($modelAbsence, 'fk_code_motif_absence', $listTypeAbsences, array('prompt' => Yii::t('view', '[tousConcernes]'), 'tabindex' => 3)); ?> </div> </div> </div> </div> <div class="control-group" style="float:left"> <?php echo CHtml::label(Yii::t('model', 'fkCodePeriodeAbsence'), 'fk_code_periode_absence', array('style' => 'control-label')); ?> <div> <?php echo $formAbsence->RadioButtonList($modelAbsence, 'fk_code_periode_absence', $listPeriodeAbsences, array('class' => 'ckPeriodAbsence', 'tabindex' => 5,)); ?> </div> <?php // echo $formAbsence->error($formAbsence, 'fk_code_periode_absence'); ?> </div> <div style="clear:both"></div> <div class="form-actions"> <?php $this->widget('bootstrap.widgets.TbButton', array('size' => 'small', 'label' => Yii::t('view', 'boutonCrer'), 'buttonType' => 'ajaxButton', 'htmlOptions' => array('tabindex' => 41), 'url' => Controller::createUrl('/demAbsence/createAbsenceDFC'), 'ajaxOptions' => array( 'type' => 'POST', 'dataType' => 'json', 'data' => 'js:$("#dfc-form-absence").serialize()', 'success' => "function(data) { $.fn.yiiGridView.update('dfc-presence-grid', {data: $(this).serialize() }); $(this).close(); }" ),)); ?> </div> <?php $this->endWidget(); ?> </div> </div> <?php $this->endWidget(); ?>
my gridview :
array( 'class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update}', 'buttons' => array( 'update' => array( 'icon' => 'tasks', 'url' => '$data->fkMesureForm->fk_mesure_id', 'label' => Yii::t('view', 'saisirAbsence'), 'visible' => '(Yii::app()->user->checkAccess("demAbsence.createAbsence") && Yii::app()->getController()->getAction()->getId() == "saisirPresence")? true : false', 'click' => 'function(){ $(\'#dialogAbsence\').dialog(\'open\'); $("#mesureId").val($(this).attr("href")); return false;}', ), ), ),
the controller :
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreateAbsenceDFC() { $modelAbsence=new DemAbsence; if(isset($_POST['DemAbsence'])) { $modelAbsence->attributes=$_POST['DemAbsence']; $modelPlanning = DfcPlanning::model()->findByPk($modelAbsence->fk_planning_id); $modelAbsence->jour_debut = $modelPlanning->jour; //$this->performAjaxValidation($modelAbsence); if($modelAbsence->save()) { echo CJSON::encode(array( 'status'=>'success', 'div'=>"absenceAjoutee" )); exit; }else{ echo CJSON::encode(array( '$modelAbsence'=>$modelAbsence, //'div'=>"absenceAjoutee" )); exit; } } }
I think I have to pass the model with erroe trough CJSON, but how can I do ?
Nath