0

I am loading a form (depending on the selected option of a dropDownList) with an ajaxcall (which triggers a renderPartial)
The ajaxcall looks like:

$("#dropDownList").change(function() {
        var selected = $(this).val();

        $.ajax({
            url: "index.php?r=item/update&category="+selected,
            cache: false,
            success: function(html){
                $("#inputs").html(html);
            }
        })
    });

The action "update":

public function actionUpdate($category){
    $model = new Item;

    $this->renderPartial($category, array(
        'model'=>$model,
    ), false, true);
}

The form will be renderd in the div "input" without any problems, but there is still no javascript available for the form. I have already used

Yii::app()->clientScript->scriptMap['jquery.js'] = false;

to prevent, that jquery will be loaded twice. But there is still no js available for my form (jquery.yiiactiveform.js).

Edit: I have checked my firebug, that jquery.yiiactiveform.js will be loaded after the ajaxcall (again?). - If I am using:

 Yii::app()->clientScript->scriptMap['jquery.yiiactiveform.js'] = false;

jquery.yiiactiveform.js isnt available anymore, so it shouldnt be loaded twice?

spyfx
  • 1,311
  • 4
  • 14
  • 24

2 Answers2

1

Your problem is mostly with scripts being reloaded. The jQuery mess everything a lot, but other scripts like YiiActiveForm also can mess up with your application. It will be best if you could preload all needed scripts on the page you call ajax and disable scripts on the pages you load with ajax. You might want to look at EUpdateDialog extension (disclaimer: written by me) it might give you some additional ideas.

  • If I am loading the scripts in my view with the ajaxcall, the scripts will exist twice (in this view), so it wont works anyway i guess – spyfx Nov 12 '13 at 19:03
  • From my personal experience when working with a similar task to yours the problem is with reloading. jQuery always gives problems, but then other scripts get reloaded sometimes they make problems also. The easiest solution is to disable them in scriptMap. My colleague also had a similar problem so he found some extension which disables the scripts if they are already loaded, but I can't remember the name of the extension so you might need to dig around Yii extensions. – Andrew Marcinkevičius Nov 12 '13 at 19:42
0

The extension @Andrew mentioned is NLSClientScript.

topher
  • 14,790
  • 7
  • 54
  • 70