Captcha 'New Code' link not working when page called via ajax

Hi,

I use Blog-Sample. I converted the Main link into ajax link (using CHtml::ajaxLink…) and for a small sample, I modified actionContact render to renderPartial.

The I checked my page, after I clicked Contact link, the ajax calls actionContact and update content DIV.

right…

Then, I realize something missing… In Contact page, there is a Captcha widget but the ‘Get a New Code’ link is missing… after digging up through this forum,

I use this: http://www.yiiframework.com/forum/index.php?/topic/88-ajax-controls-and-render-partial-not-being-bound/page__view__findpost__p__439

Now the link is showed up.

right…

Now, the problem is, the link is not working, I checked the JS code (via firebug) an notice, that the JS for the ‘Get a New Code’ is missing…

So, any help for this? or is it somehow, related to this ticket http://code.google.com/p/yii/issues/detail?id=38 ?

EDIT:

Well, if the refresh code is by clicking the image, then it works though…

here the code in the view


<?php $this->widget('CCaptcha', array('clickableImage'=>true, 'showRefreshButton'=>false)); ?>

Normally JavaScript code supplied by widgets or components will be registered by yii at certain position in the actual page. Mostly the POS_READY position is used. Which means that the code will be place in at the end of the page in the ready function. If you use renderPartial to update a container via ajax the function that renders the js code will never be invoked.

If you retrieve parts of the page, you have to make sure that your js code is delivered with it and not through the register script function of yii.

Thats why ‘clickableImage’ works because the js part is placed as an ‘onClick’ attribute of the img tag.

So, the Capthca widget need fixing. Thanks for the information.

what about this problem? are there any useful solutions or fixes?

PUSH 8)

Yes, abandon the use of ajaxLink(). See this thread here.