Creating an ajaxButton inside a piece of page loaded via ajax


I have a page with an ajaxLink() that replaces a part of the pace with a form it loads. In the form, I have created an ajax button that will replace again the form with the output of the update action.

The ajaxLink works fine, but the ajaxButton doesn’t. The javascript code for it simply isn’t anywhere.

Is there a way to get it to work?

I have already taken care to assign unique id’s to the links and the buttons.

I’ve noticed that the way ajaxlinks and ajaxbuttons work is that they have an unique id, and then there’s a piece of jquery code at the beginning of the page that assigns the onclick behavior to the node selecting it by id.

But this part of the code is only generated in the containing page, which can’t know that later I will load a piece of page that contains other buttons.

Is there a way I can get this to work taking advantage of the framework, or do I have to write the javascript code from scratch in this case?




I guess you should post the relevant parts of your view and controller…


I’ve figured out: the problem was that I was using renderPartial to render the view that got loaded dynamically.

The generation of the actionscript code for ajax buttons and links is performed when rendering the layout, so in order to have it working I had to render the view with render(), not renderPartial(). I created an empty layout for it (with just an ‘echo $content;’) and now it works.

The built-in way to do this is to set the fourth parameter in the renderPartial() call to true.



This tells Yii to include the JS required for the ajax button to work.