The problem is, that the (most of all) widgets use 'clientScript->registerScript' to publish the js-code.
But this will not work in a ajax-response and the script will not be executed.
And (perhaps?) globally registered jQuery functions cannot be used in the ajax response (needs more investigation...).
Also the CHtml::clientChange uses 'registerScript' and I have sometimes problems with that.
The problem is similar to renderPartial, with processOutput=false.
If I work with my own ajax-response controllerAction, this is no problem, but the problem are the widget extensions.
In most cases I can override the widgets registerClientScript method like below and it works:
class MyAjaxReadyWidget extends SomeWidget { public $directOutput = null; //= autoMode: check for ajax public function init() { if($this->directOutput == null) $this->directOutput=Yii::app()->request->isAjaxRequest; parent::init(); } public function registerClientScript() { if($this->directOutput) { $jsScript = ... nearly the same as in the parent ... echo CHtml::script($jsScript ); } else parent::registerClientScript(); }
Am I missing another solution for that problem?
I would like to see a workaround for this problem in the core.
1. place libraries/functions in the main view (jQuery,....) that can be used in the ajax-response.
2. a 'directOutput' feature in the core CWidget that processes the js-code immediatly in the run() method.
Maybe it should be possible to 'register' scripts in the ClientScript for 'directOutput' too, not only the current 'registerScript'.