Hi all,
I have a form with 2 date zones where I am using CJuiDatePicker. I have also on the same form a CHtml:ajaxButton which I use to create customer data if the latter does not exist. This avoids the user to have to leave the form, create the customer data and return to the form. I have noted that when I do not have to create the customer, the datepickers for the 2 dates work fine. They stop working when I use the Chtml:ajaxButton to create customers. How do I reactivate the datepickers? I tried to use afterajaxupdate but it did not work. Here is my code:
Form view
<tr>
<td colspan="2">
<div id="cl">
<?php echo $form->dropDownList($model,'client',
CHtml::listData(Client::model()->findAll(array('order'=>'name ASC')), 'id_client', 'FullName'),array('prompt'=>'Select')); ?>
<?php echo CHtml::ajaxButton(Yii::t('cl','New Client'),$this->createUrl('client/addnew'),
array('onclick'=>'$("#clDialog").dialog("open"); return false;','update'=>'#clDialog',
'afterAjaxUpdate'=>"function(){jQuery('#arr,#dep').datepicker({'dateFormat': 'dd-mm-yy'})}",), // does not work
array('id'=>'showClDialog'));?>
<div id="clDialog"></div>
</div></td>
<td colspan="2"><?php echo $form->dropDownList($model,'roomtype',
CHtml::listData(Roomtype::model()->findAll(), 'id', 'DescripId'),array('class'=>'room','id'=>'rmtype')); ?>
<?php echo $form->error($model,'roomtype'); ?></td>
</tr>
</table>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => CHtml::activeName($model, 'arrival'),
'model'=>$model,
'id'=>'arr',
'value' => $model->arrival,
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'dd-mm-yy'
),
'htmlOptions'=>array(
'size'=>10,
),
));
Action addnew in client controller:
public function actionAddnew() {
$model=new Client;
// Ajax Validation enabled
//$this->performAjaxValidation($model);
// Flag to know if we will render the form or try to add
// new client.
$flag=true;
if(isset($_POST['Client']))
{ $flag=false;
$model->attributes=$_POST['Client'];
if($model->save()) {
//Return an <option> and select it
echo CHtml::tag('option',array (
'value'=>$model->id_client,
'selected'=>true
),CHtml::encode($model->Fullname),true);
}
}
if($flag) {
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('createDialog',array('model'=>$model,),false,true);
}
}
Thanks beforehand