Ajax controls and render partial not being bound

Hi

If you do a renderPartial on a view containing an ajax control then the controls' event is not bound in JQuery. For example you do an ajax update on a page and the view you are partially rendering has a CHtml::ajaxLink. The methods for binding the ajaxLinks' click event is not sent back to the client. 

Sound like a bug ?

nz

Could you show me the code about your ajaxLink call and the relevant HTML elements that you want to update?

In the view s

View viewa



<div class="mainBody">


<% $this->renderPartial("bview",array("dirList"=>$this->getDirList())); %>


</div>


View bview






<%


foreach $dirList as $n=>$dir) {


  CHtml::ajaxLink ($n,array('folder','reference'=>$dir),


          array('update'=>'.mainBody'));


}


%>





controller






public function actionFolder() {


$reference = $_GET['reference'];


$this->renderPartial("bview",array("dirList"=>$this->getDirList($reference)));


}


public function actionIndex() {


    $this->render("viewa");


}





I couldn't reproduce the issue.

Try to directly access the 'folder' action in your browser to make sure it works as expected.

Use FireBug to see if there's any error when clicking the link.

If there's still problem, please post the generated HTML page here.

Hi

The page loads correct and the first request works, but the response has only the following in it



 <div>


    <a href="#" id="yt0">niceimport</a>  <a href="#" id="yt1">nice.</a>  <a href="#" id="yt2">nice..</a>


  </div>


  <div>


  


  </div>


So the second time I click the generated link no new request is made (I am on firefox watching with firebug).

The response I would have expected to come back should have included the script to bind the anchors to jquery but does not

I see what's the issue.

I just checked in a fix. Please change your renderPartial call and add a parameter value "true" as the fourth parameter. This will instruct Yii to append the generated javascripts.

Bingo working !

thanks K++

nz

I try this and i can't make it work.

It only works the first time.

I put this code on the Folder Action:

	public function actionFolder() {


		$reference = $_GET['reference'];


		$this->renderPartial("bview",array("dirList"=>$this->getDirList($reference)),false, true);


	}

And also tried

	public function actionFolder() {


		$reference = $_GET['reference'];


		$this->renderPartial("bview",array("dirList"=>$this->getDirList($reference)),true);


	}

Is there something else to do?

Update the framework?

You need to make sure you are using the latest from SVN (R114 I think)

Thanks!

Hi

I have noticed this appears to be an issue again in version 1.0.1

What used to be a response was



</table>


<script type="text/javascript">


/*<![CDATA[*/


jQuery('#yt0').click(function(){jQuery.ajax({'url':'/cart/index.php?r=gallery/folder&reference=%2Fhome


%2Ffoo%2Fpublic_html%2Fcart%2Fimages%2FShots%2Fimport%2Felse','cache':false,'success':function(html


){jQuery(".mainBody").html(html)}});return false;});


jQuery('#yt1').click(function(){jQuery.ajax({'beforeSend':function(){alert("a")},'url':'/cart/index.php


?r=gallery/folder&reference=%2Fhome%2Ffoo%2Fpublic_html%2Fcart%2Fimages%2FShots%2Fimport%2Felse','cache'


:false});return false;});





Now the response is



</table>


<script type="text/javascript">


/*<![CDATA[*/


jQuery(document).ready(function() {


jQuery('#yt0').click(function(){jQuery.ajax({'url':'/cart/index.php?r=gallery/folder&reference=%2Fhome


%2Ffoo%2Fpublic_html%2Fcart%2Fimages%2FShots%2Fimport%2Felse','cache':false,'success':function(html


){jQuery(".mainBody").html(html)}});return false;});


jQuery('#yt1').click(function(){jQuery.ajax({'beforeSend':function(){alert("a")},'url':'/cart/index.php


?r=gallery/folder&reference=%2Fhome%2Ffoo%2Fpublic_html%2Fcart%2Fimages%2FShots%2Fimport%2Felse','cache'


:false});return false;});





Notice how the second response is wrapped in the "jQuery(document).ready(function()". I think this may be the issue.

The render partial is called like



$this->renderPartial("galleryBody",array("fileList"=>$this->getFileList($reference)), false, true);


Did you want me to log an issue for this ?

nz

Hmm…I didn’t realize this. This is also related with ticket #38. Could you please report your problem in that ticket? No need for a separate ticket. We need some nice way to solve this issue.

I have fixed this issue in SVN.

Verified, R480 CClientScript corrected the issue

Thanks

nz