开发者

Collapsible fieldsets not working for UNauth'd users in Drupal?

开发者 https://www.devze.com 2023-01-27 00:15 出处:网络
Hey there, I have used the same method that drupal/jquery uses that allows for collapsible fieldsets on some of drupal\'s option pages as a categorization method for one of my nodes. It works perfectl

Hey there, I have used the same method that drupal/jquery uses that allows for collapsible fieldsets on some of drupal's option pages as a categorization method for one of my nodes. It works perfectly if I'm logged in, and not at all if I'm not. It's as if something is not being called, but as far as I can tell t开发者_Python百科he 3 js files I'm calling from w/ in the node are in the code when I 'view source'... ?

Here are the details:

  • Collapsible fieldsets inside of a basic node ("story" content-type).
  • Drupal 6
  • Works logged in
  • Doesn't work logged out

Any help would be greatly appreciated! Let me know if any further clarification would be helpful. Thanks! TE


Okay, for any of those who might have experienced a similar problem... Most of the 'how-to' pages on getting collapsible fieldsets working w/in a node tell you to add the js files (via the php filter) with syntax like <script src="/misc/blah.js"></script> This seemed like it should work, and did when I was an authenticated user. But it broken when I was not logged in...

The solution was to use actual php code and drupal's drupal_add_js call to integrate the appropriate scripts. Such as <?php drupal_add_js("/misc/blah.js"); ?> .

All's good now, collapsible fieldsets functioning properly in generic node content! ;)

Complete sample code for those who might want to use it. Make sure you have the php input-type enabled and copy/paste this into your body area (code view/wysiwyg's off!):

<?php
    drupal_add_js("/misc/jquery.js?O");
    drupal_add_js("/misc/drupal.js?O");
    drupal_add_js("/misc/collapse.js?O");
?>

<div>

    <fieldset class="collapsible collapsed">
        <legend>MAIN CATEGORY</legend>
        <div>

            <fieldset class="collapsible collapsed">
                <legend>Sub Category</legend>
                <div>
                    <p>Stuff and such...</p>
                </div>
            </fieldset>

        </div>
    </fieldset>

</div>


The solution provided by TwstdElf didn't quite work for me.

I ended up having to insert some JavaScript at the hook_init of one of my modules:

$inline_js = "
$.getScript('/misc/collapse.js', function() {
  $.getScript('/misc/drupal.js', function() {});
});";

drupal_add_js($inline_js, 'inline');

This is the only thing that worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消