Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to fix ctools_add_js() not working issue in ctools modal form in drupal 7.x

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.33k
    Comment on it

    Hi All,

    I am sharing my recent experience with C-Tools modal form, I was adding custom js file in ctools modal form in Drupal 7.x using jQuery version 1.8

    ctools_ad_js();

    and add my code under

    document.ready(),

    but my code didn't work and I am sure the code has no issue as the same code was working absolutely fine when I was adding the js without using ctools modal form.

    After making a lot fight on google I got a solution that with jQuery version 1.8 or greater, ctools modal form will not work with document.ready, instead of using this, you must have to use Drupal.behaviors, if you want to add custom jQuery code.

    So it's a suggestion if anyone stuck with such an issue, go head with Drupal.behaviors in the following manner and it really works:

    Sample Code:

    (function ($, Drupal, window, document, undefined) {
               Drupal.behaviors.my_custom_behavior = {
                                 attach: function(context, settings) {
                                       /// your code goes here
                                 }
                  };
    })(jQuery, Drupal, this, this.document);

    If you want go in deep, you can refer this link to understand more about drupal behaviours:

    https://drupal.org/node/756722#behaviors

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: