user->setFlash() "Javascript -Success-FadeOut" doesn't work in renderPartial()

Hi guys,

Via an AjaxButton I re-render the content of a partial view file called _Xview.php (without refreshing the entire site…)

When the _Xview.php view gets re-rendered the success Message shows up… However the success message doesn’t fade out (via javascript). It stays forever.

Why doesn’t it fade out? The code used works in other views where the entire site is refreshed?

Here is the Controller Code…




...

....

Yii::app()->user->setFlash('success',"THX we got your vote..");  

$this->renderPartial('../like/_Xview',array('model'=>$model));



Here is the Code of the _Xview.php view that gets called via partialRender() from my Controller:







<?php if(Yii::app()->user->hasFlash('success')):?>

    <div class="flash-success">

        <?php echo Yii::app()->user->getFlash('success'); ?>

    </div>

<?php endif; ?>


<?php

Yii::app()->clientScript->registerScript(

   'myHideEffect',

   '$(".flash-success").animate({opacity: 1.0}, 3000).fadeOut("slow");',

   CClientScript::POS_READY

);

?>







..<img src="imagefilledrectangle.png">..<br>




Here is the code where the partial view file is embedded in:








$this->menu=array(

	array('label'=>'List image', 'url'=>array('index')),

	array('label'=>'Create image', 'url'=>array('create')),

	array('label'=>'Update image', 'url'=>array('update', 'id'=>$model->idImage)),

	array('label'=>'Delete image', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->idImage),'confirm'=>'Are you sure you want to delete this item?')),

	array('label'=>'Manage image', 'url'=>array('admin')),

);

?>







<h1><?php echo $model->titel; ?></h1>




<div id="data">

	<?php $this->renderPartial('../like/_Xview.php',array('model'=>$model)); ?>

</div>




other Stuff..






You need to load jquey. have You loaded jquery? You may see via firebug. if not pleasee add following statement:


Yii::app()->clientScript->registerCoreScript('jquery');

mhh… added the line…

Unfortunately still not working.

Any other ideas?

THX

The first time you render the _Xview a js code is registered as POS_READY… so that function is called as soon as the page is rendered… not any more…

even if you re-render that part (with AJAX)… this function is not executed anymore…

so you need a way to call that js code everytime you re-render that partial view…

best way would be to assign that function to the ajax button… first make the ajax call… after that execute this function…

Ok Thx… that makes sense…

Could you please show how to add it to the button…

I included my _xView.php View below… including the buttons.





<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>




<?php if(Yii::app()->user->hasFlash('success')):?>

    <div class="flash-success">

        <?php echo Yii::app()->user->getFlash('success'); ?>

    </div>

<?php endif; ?>


<?php

Yii::app()->clientScript->registerScript(

   'myHideEffect',

   '$(".flash-success").animate({opacity: 1.0}, 3000).fadeOut("slow");',

   CClientScript::POS_READY

);

?>





Content Stuff here...




<?php echo CHtml::ajaxButton ("Like",

                              CController::createUrl('image/likeAjax&like=1&idImage='.$model->idImage), 

                              array('update' => '#data')); // #data is the id of the div tag which includes the renderPartialCall

?>