Ajax form Events lost when form refreshed

Hello all,

I have a page in which I render the entire page complete (including the ActiveForm) and after the page is loaded, I remove the form $(jquery).remove("ddd") and

then use ajax to load the form again (with new values from model) when a user clicks a button. The problem is once I refresh the form like this I loose my event attachments generated originally from ActiveForm that was loaded the first go around.

  1. I did it this way so that all scripts would be preloaded and in theory if I replaced the form the events would be attached (which they are not). Was hoping they were jquery delegates…

At the bottom of the page in the script section is automatically generated call


If I were to call this above in my jquery function, everything works on my active form as it should. But that requires me to copy and paste that snippet and place it in my jquery loading function. If I change the form, that has to change as well.

Is there anyway to make this call again? What am I doing wrong on this page? How can I get my form to call that or create that snippet again?


Problem for the most part resolved.

  1. Remove old form $(this).remove()

  2. Changed render partial to $this->renderAjax (which delivered the scripts) in my ajax call to the controller when rendering the form.

So now all validation works. The only problem is that the form is delivering back <script> calls

<script src="/sunnybears/web/assets/3541c4b6/yii.js"></script>

<script src="/sunnybears/web/assets/3541c4b6/yii.validation.js"></script>

<script src="/sunnybears/web/assets/3541c4b6/yii.activeForm.js"></script>

<script type=“text/javascript”>jQuery(’#form1’).yiiActiveForm(… (THIS IS WHAT I WANTED)

Will loading these scripts again cause any problems? Firebug does not show these scripts loading again.