Reputation: 65
I am new to Yii framework.i posted this many time but no reply.
I have date field in a registration form with cjuidatepicker
widget.
This widget working well in a static page, but when I use it in a popup form, this widget does not appear.
Any advice would be appreciated.
A Link to open a pop-up dialog, its code is here.
<?php
echo CHtml::link('Add Client ', "",
array(
'style'=>'cursor: pointer; font-size:20px; text-decoration: underline;',
'onclick'=>"{addclient(); $('#dialogclient').dialog('open');}"
)
);
?>
cjuidatepicker
widget code:
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'value'=>'p_end_date',
'attribute'=>'p_end_date',
// additional JavaScript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;',
),
));
UPDATED EDIT: code for rendering / opening a _from.php using url
<script type="text/javascript">
// here is the magic
function addclient()
{
<?php echo CHtml::ajax(array(
**'url'=>array('client/create'),**
'data'=> "js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if (data.status == 'failure')
{
$('#dialogclient div.divForForm').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#dialogclient div.divForForm form').submit(addclient);
}
else
{
$('#dialogclient div.divForForm').html(data.div);
setTimeout(\"$('#dialogclient').dialog('close') \",3000);
}
} ",
))
?>;
return false;
}
</script>
Actioncreate() controller CODE
public function actionCreate()
{
$model=new client;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['client']))
{
$model->attributes=$_POST['client'];
if($model->save())
{
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'success',
'div'=>"Client successfully added"
));
exit;
}
else
$this->redirect(array('view','id'=>$model->id));
}
}
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'failure',
'div'=>$this->renderPartial('_form', array('model'=>$model), true)));
exit;
}
else
$this->render('create',array('model'=>$model,));
}
Upvotes: 1
Views: 5393
Reputation: 3677
when you rendering the page on the popup use renderPartial
with following flags, set 4th argument processOutput
to true
$this->renderPartial('view',array('model'=>$model),false,true);
http://www.yiiframework.com/doc/api/1.1/CController#processOutput-detail
Upvotes: 3
Reputation: 1237
What I guess is the import code for cjuidatepicker widget is not in the new pop up window. When the pop up window opened, go to the source code and see whether all the js imports are there?
Upvotes: 2