Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Forms » How to avoid duplicate data when using ActiveForm on AJAX forms
1 Vote
Vote Con!
Solved!

How to avoid duplicate data when using ActiveForm on AJAX forms

AJAXCActiveForm

When I am displaying an active form with AJAX, I see on firebug how certain files are downloaded constantly -ie. jquery.js, jquery.yiiactiveform.js. Anybody has any idea on how to solve that?

By tonydspaniard in Forms · Asked 618 days 22 hours 57 mins ago

Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0

 

Answers (6)

  1. 1 vote
    Accepted

    Problem is that on render the needed JS scripts are rendered too… To avoid this use

    1. Yii::app()->clientScript->corePackages = array();
    Yii::app()->clientScript->corePackages = array();

    Note that in this case you need to manually include jquery.yiiactiveform.js in your main view.

    By mdomba · 618 days 22 hours 48 mins ago

    Questions: 1 Accepted: 0 ( 0% ) | Reputation: 0

    • That makes sense...

      By admin · 618 days 22 hours 47 mins ago

  2. 1 vote

    This can get more complicated once you start using more components which uses more JS (and even CSS) files. I’ve found a solution which I’m quite happy with, which basically allows Yii to register all JS and CSS as per usual. The actual fix is a hook on jQuery’s ajax filtering, which removes any duplicate CSS and JS references. For up to date source, check http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/

    By eirikhm · 618 days 23 mins ago

    Questions: 1 Accepted: 0 ( 0% ) | Reputation: 0

    • Your idea is really nice and it works... but still the duplicate script files (jquery, yiiactiveform, yiigridview, ...) are downloaded/sent to the browser. I personally like more the solution that does not even send that files as they are not needed.

      By mdomba · 612 days 20 hours 41 mins ago

  3. 0 votes

    Another hint is to use renderPartial function if possible and set the fourth parameter to TRUE. This will process output and JS script tags are correctly inserted at appropriate places.

    By kokomo · 612 days 20 hours 58 mins ago

    Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0

    • With the 4th parameter set to true, all output will be processed and that's why a duplicate jquery file will be downloaded... that is the problem discussed in this thread :)

      By mdomba · 612 days 20 hours 44 mins ago

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site