Difference between #1 and #2 of
Avoiding duplicate script download when using CActiveForm on Ajax calls

Changes

Title unchanged

Avoiding duplicate script download when using CActiveForm on Ajax calls

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

tutorial, AJAX, CActiveForm

Content changed

[...]
Sometimes the active form we wish to use to edit/add a new element on our database is too small and we believe that is much better to use an AJAX'ed dialog/slide form rather than reloading the page to just display one or two fields.

The only thing required is simple, we just need to create a view that will be partially rendered by a call to a controller (using renderPartial) and make sure that we process output -setting to true the parameter on the function. Everything will work as expected but...

###The issue
If we open firebug (firefox), or developer tools (chrome), or whatever the tool you use in order to see the XmlHttpRequest object calls and resources downloaded, you will see that every time we do call the controller to display the active form,
jquery.yiiactiveform.jdifferent Yii "core JS" files keeps being downloaded to the client. The JS files downloaded depends on your code but there are at least jquery.js, jquery-ui.js and jquery.yiiactiveform.js.

###The solution
The solution is a bit tricky but simple. We need to pre-render the jquery.yiiactiveform.js on the view where we are going to place the AJAX functionality (the button that opens the modal dialog or slides/shows a layer with AJAX'ed form contents). For example, on index.php view file:

```php
[...]
11 1
9 followers
Viewed: 27 215 times
Version: 1.1
Category: Tutorials
Written by: Antonio Ramirez
Last updated by: Maurizio Domba Cerin
Created on: Sep 11, 2011
Last updated: 13 years ago
Update Article

Revisions

View all history