After diving into the related issues, it's apparent that we need to wrap core's misc/collapse.js so modules that utilize it's API can trigger the Bootstrap collapse plugin instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

  • Commit 517c8c0 on 7.x-3.x by Mark Carver:
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
markhalliwell’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev
Assigned: Unassigned » ryan.armstrong
Status: Active » Needs review

  • Commit 979a20a on 7.x-3.x by Mark Carver:
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
    Fixed...

  • Commit 517c8c0 on 7.x-3.x, 8.x-3.x by Mark Carver:
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
  • Commit 979a20a on 7.x-3.x, 8.x-3.x by Mark Carver:
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
    Fixed...
steveixa’s picture

I'm using Bootstrap theme and am finding that my collapsible fieldsets aren't working. I click on them but they just stay as they are. Is there a workaround short of upgrading my theme to the dev version?

thanks

steveixa’s picture

I'm experiencing this problem in Drupal 7. I tried upgrading to the dev version of the theme but it broke my site. How can I apply the fix for this problem.

thanks

steveixa’s picture

bump

markhalliwell’s picture

It was fixed in 7.x-3.x-dev (subsequently there's now a 7.x-3.1-beta1 release). View the release notes so you can upgrade.

steveixa’s picture

ok - thanks for replying.

I did try that but it really messed up my site. Also, it didn't fix the issue with Collapsible fieldsets not expanding and collapsing.

any workarounds?

thanks

  • Mark Carver committed 517c8c0 on 8.x-3.x.x
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
  • Mark Carver committed 979a20a on 8.x-3.x.x
    Issue #2224211 by Mark Carver: Fieldset #collapsible broken.
    
    Fixed...
markhalliwell’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
Assigned: ryan.armstrong » Unassigned
Status: Needs review » Closed (fixed)

I'm just moving this back to 7.x. If this needs re-evaluation in 8.x, create a new issue.

iaminawe’s picture

Status: Closed (fixed) » Needs work

Using 7.x-3.1-beta1 and manually applying the updates from #10 I still find that drupals collapsible fieldsets are not working properly.
I tried to update to beta2 but so much broke that I needed to roll back and try just fix this component.

Here is the markup being output - clicking on the expand/collapse header does nothing. Does this look correct to you?

<fieldset class="collapsible group-test field-group-fieldset panel panel-default form-wrapper collapse-processed" id="bootstrap-panel">
          <legend class="panel-heading">
      <a href="#" class="panel-title fieldset-legend" data-toggle="collapse" data-target="#bootstrap-panel .collapse">
    <span class="fieldset-legend-prefix element-invisible">Hide</span>Test</a>
    </legend>
    
<div class="panel-collapse collapse fade in">
    <div class="panel-body">
     The content
    </div>
    </div>

  </fieldset>

Then I thought I should try with the latest 3.x dev of Bootstrap in a fresh local install of Drupal - I set this up and made a simple collapsed group on a node

It worked the first time I clicked the title and it opened the collapsed container and then closed when I clicked again and then would not reopen again.
I was able to replicate this a few times where only the first open and close works and then it stops responding.

Any thoughts?

markhalliwell’s picture

I tried to update to beta2 but so much broke that I needed to roll back and try just fix this component.

This is because the grid stuff was actually reverted (#2128129-19: Provide setting to change sidebar/content widths). It sounds like you're one of the very few people who used dev/beta for prod (which is never recommended btw, for this very reason). I can tell you with fair amount of certainty that beta2 will not break on upgrade from 7.x-3.0 (like beta1 did). It does, however, break upgrading from beta1 (which is what sounds like your issue is). I would strongly recommend fixing your sub-theme to work with beta2 as this is the path we'll be moving forward with for the next release. I know this isn't ideal, but I would much rather face the wrath of a hundred people than 30k ;)

Then I thought I should try with the latest 3.x dev of Bootstrap in a fresh local install of Drupal - I set this up and made a simple collapsed group on a node

Are you manually injecting this HTML? Or is this generated in PHP somewhere? If that is the case, can you provide the PHP snippet so I can attempt to reproduce?

iaminawe’s picture

Thanks for the response Mark and great work with this theme.

This site has actually been in development (so is not prod yet) and I think the only reason I updated it to beta1 was to be able to generate the sub theme with drush - didn't realize the pain it may cause as its been solid to work with up until this point.

On the fresh install, I simply added a group to the display settings of the article content type and put a few fields inside of it.
I then added some test content and when viewing the node I was able to open and close the fieldset once before it stopped responding.

I did try to fix/update my sub theme to work with beta2 but it felt like it was too quickly becoming a rabbit hole of broken things.

All the region templates seem to have been removed in Beta2 and the page variables I was loading into the regions were broken and I was told in a warning that the $page variable no longer exists for the region templates - I did some troubleshooting but was not able to figure out what had changed to break that.

So to fix my sub theme to work with beta2 - I should attempt this patch? https://www.drupal.org/comment/9009607#comment-9009607

Would downgrading to 3.0 stable be a better course to take?

markhalliwell’s picture

Would downgrading to 3.0 stable be a better course to take?

Yes. That being said, the similarities between 3.0 and beta2 (as far as page.tpl.php and regions go) are very similar. You will undoubtedly run into quite a few bugs though on 3.0 (it's old). So I would recommend going with beta2 for now as we're very close to a stable release at this point.

The only reason we haven't made a release was because of that grid issue (breaking straightforward upgradability from 3.0). Normally, beta's should break like this and in reality (and in hindsight) they should probably be alphas. We live, we make mistakes, we move on :)

Anyway, now that the grid stuff has been reverted, I suspect you'll simply have to remove (rename/backup) your sub-theme's page and region templates. Then, just let the base-theme templates take over (things will obviously be broken if you had them overridden). Once you're at a starting point you can slowly copy in the old template changes (keeping in mind that all the region stuff will likely be back in the page template). So in the end, you'll likely have just one page template override and no region template overrides (because we really didn't use regions in 3.0).

So to fix my sub theme to work with beta2 - I should attempt this patch? https://www.drupal.org/comment/9009607#comment-9009607

I wouldn't. That was just to record the changes that I took out, so we have a starting point and can refactor. As stated in that issue, I was never really happy with that implementation (which should have been a sign that I shouldn't have committed it). So until we can come up with a better implementation that doesn't break everything, I would just hold off.

Now, regarding this issue. Did you see my question above:

Are you manually injecting this HTML? Or is this generated in PHP somewhere? If that is the case, can you provide the PHP snippet so I can attempt to reproduce?

iaminawe’s picture

Thanks for the clarifications Mark, that certainly helps me with getting my sub theme upgraded. I am going to attempt this again shortly.

That markup was , I believe, copied and pasted from the node display where the fieldset was defined on the "Manage Display" page so there was no manual injection or php snippet - just the normal node display.

I will report back here after the subtheme upgrade whether the fieldset collapsing still is or isn't working

iaminawe’s picture

Status: Needs work » Fixed

Following your instructions, I was able to upgrade my subtheme correctly.

At first the fieldsets behaved exactly the same and opened and closed once fine before locking up.
I checked the jquery update setting and it was still at 1.7 - after updating the version to 1.9 the fieldsets opened and closed correctly again.

Thanks for you help with this issue and my upgrade - sorry that it ended up being something silly on my side.

markhalliwell’s picture

Status: Fixed » Closed (fixed)

Ah :) Yep, that'll do it! Cool, glad this got resolved relatively easily!

oriol_e9g’s picture

Status: Closed (fixed) » Active

I'm am using Bootstrap-3.1-beta2 with webform module and collapsible fields only works one time.

When the HTML is rendered appears like:

<div class="panel-collapse collapse fade in">

When I click to the collapsible fieldset works fine and it's collapsed:

<div class="panel-collapse fade collapse" style="height: 0px;">

When I click again to open the fieldset works and the HTML is converted as:

<div class="panel-collapse fade in" style="height: auto;">

See that the 'collapse' class has disappeared, so at this point you cannot collapse again the fieldset. The fieldset works but only the first time you collapse-open the fieldset.

Plazik’s picture

Update Bootstrap css and js to 3.2.0 version.

markhalliwell’s picture

Status: Active » Closed (fixed)
oriol_e9g’s picture

@Plazik Yes! I can confirm that using Bootstrap 3.2 css/js it's working fine.

MauPalantir’s picture

Its not working for me, because after I close and open once again, i can't close.
i figured out that somehow the 'in' class is not removed properly. I made a patch that fixes it, though I dont know it is the best place to remove the class.

theo_’s picture

Same issue here as mentionned by @Mau Palantír
Using:

  • bootstrap theme 7.x-3.1-beta2+8-dev (commit e014953)
  • boostrap library 3.2.0

Re-rolled patch to apply on last 7.x-3.x-dev version

markhalliwell’s picture

See #17 and verify your jQuery version is set properly. Bootstrap should remove the "in" class automatically in it's own JS, these patches shouldn't be necessary.

justindodge’s picture

Status: Closed (fixed) » Needs review
FileSize
681 bytes

I'm using jQuery 1.9 and the latest 7.x-3.x dev of bootstrap module.
I've tried bootstrap library 3.2.0 and the latest 3.3.4 and I'm getting the behavior described in #19 and #23 where the fieldset will expand one time, but subsequent clicks do nothing.

I also gave the patch in #24 a shot but it did not resolve the issue for me.

Maybe there has been a regression? Can anyone else reproduce?

I took a closer look and it seems like the problem is the data target looks for #theelementid > .collapse, but .collapse seems to be the class that bootstrap uses to hide the collapsible content (it's display:none), and the class gets removed in the process of toggling, so it can't work again after you've expanded it once.

I wrote a patch which changes .collapse to .panel-collapse as the target, and it's working great for me now.

markhalliwell’s picture

Status: Needs review » Closed (fixed)

Please, stop re-opening closed issues (especially ones that have already been fixed, #10). Open a new one and reference other issues via the related issue field.

For the record, no, I cannot reproduce this with the latest dev code and Bootstrap 3.3.4.

Also, this project is not a module, it is a base-theme.

justindodge’s picture

Well it seemed like this was a continuance of the same issue, had relevant background in comment history, and potentially was not never fixed because I was not able to reproduce any circumstances where it ever worked given the previous suggestions.

To me, it seemed like a possibility that perhaps the collapsible fieldsets only seemed like they were working because because testers may have clicked on them once, saw activity, and assumed success - or something like that. Sometimes things are preemptively closed when folks stop following up. Perhaps I needed to read the history more thoroughly.

I've never posted on any issue with the bootstrap project before so I don't think I need to be told to stop re-opening things... I've tried to provide a rationale for this and it seems issues sometimes go from 'fixed' to 'active' for reasons like this, but everyone has their own way.

Anyway, apologies for the mix up and I will open a new one and see if we can get to the bottom of it.

justindodge’s picture

No new issue after all - after some head scratching, it turns out I was simply looking at the base theme's settings for the Bootrap JS/CSS version by accident when I was actually using a sub-theme which apparently defaults to 3.0.2.

So the data target thing was a total red herring...and I was so sure there was a problem. Anyway...

Sorry about the chatter, carry on.

Bruno Vincent’s picture

I'm very much confused about this whole thread...

I'm using the latest version of Drupal 7.38 with latest

http://ftp.drupal.org/files/projects/bootstrap-7.x-3.0.zip

Now July 7 2015

Can somebody point out the DEFINITE solution to this?

Some many thread answers...

What will actually work?

Thanks

markhalliwell’s picture

@Bruno Vincent, 7.x-3.0 will always be broken (nothing anyone can really do about that, unless you want to try and piece together the many issues that fixed it and patch it yourself). Instead, I recommend upgrading to 7.x-3.1-beta2 (where this has "definitely" been fixed).

BigEd’s picture

@Bruno Vincent

To fix this issue just make sure you are using at least 7.x-3.1-beta2.

Go to yoursite.com/admin/appearance/settings/bootstrap

On the advanced tab set the version to 3.4

As a good measure do the same on your subtheme settings.

Now they will work

chup’s picture

@BigEd
Sorry, but you posted a strange comment.

On mid of September 2015 there is no 3.4 version of Bootstrap (last one is 3.3.5). So, we definetly can't use 3.4 on the CDN settings of theme.

And 7.x-3.1-beta3 still not fixed this issue. The fieldsets became even worse: supposed to be collapsed by default here shows like opened and don't reacting to click at all. So we're still there :(

chup’s picture

The problem in my case was with fieldsets provided by Field Group module. Despite on settings, panel was always open without possibility to click on it. I made some quick research and fixed it.

For case of Field Group fieldsets problem is in the bootstrap_preprocess_bootstrap_panel():

// Force grouped fieldsets to not be collapsible (for vertical tabs).
  if (!empty($element['#group'])) {
    $variables['collapsible'] = FALSE;
    $variables['collapsed'] = FALSE;
  }

This code just overlapping real collapsible state and all further logic just not runs. So adding it up again in our theme.

Quick fix for broken collapsible fieldset (bootstrap-7.x-3.1-beta3)

Just add the following code to template.php of your Bootstrap subtheme:

function bsub_preprocess_bootstrap_panel(&$variables) {
  $element = &$variables['element'];
  $attributes = &$variables['attributes'];

  if (!empty($element['#group']) && $element['#collapsible'] != $variables['collapsible']) {
    $variables['collapsible'] = TRUE;
    $variables['collapsed'] = TRUE;

    if (!isset($element['#id'])) {
      $element['#id'] = drupal_html_id('bootstrap-panel');
    }

    $attributes['id'] = $element['#id'];
    $variables['target'] = '#' . $element['#id'] . ' > .collapse';
  }
}
arthur_drupal’s picture

For me, i have to add this in order collapsible fieldset work with bootstrap :

/**
 * Implements hook_field_group_pre_render_alter().
 */
function MODULE_field_group_pre_render_alter(&$element, $group, & $form) {
  if($element['#type'] == 'fieldset' && !isset($element['#id'])){
    $element['#id'] = drupal_html_id('fieldset');
  }
}

Moreover, remove Drupal default collapsible javascript

/*
 * Implements of hook_js_alter
 */
function HOOK_js_alter(&$js) {
  unset($js['misc/collapse.js']);
}
orcode’s picture

I found that simply setting the Bootstrap SubTheme Bootstrap version to 3.3.5 seems to solve the collapsible fieldset issue - without additional modifications to template.php. I'm using Bootstrap-7.x-3.1-beta3 as a base.

knalstaaf’s picture

If none of the above does the job there's still the manual approach:

jQuery(document).ready(function ($) {
    var divs=$('.views-widget').hide(); // Hide/close all containers that have this class name

    var collabel=$('.views-exposed-widget label').click(function () { // element with this class name will be clickable to collapse the containers
        collabel.not(this).removeClass('active')
        $(this).toggleClass('active')
        divs.not($(this).next()).slideUp() // makes sure only one container is expanded. Remove if you want to allow more than one open container
        $(this).next().slideToggle()
        return false; // Prevent the browser jump to the link anchor
    });
});

(Tested on Bootstrap-7.x-3.1-beta3 / Bootstrap 3.3.5 - source)

Edit: this method will collapse the item(s) again after a reload of the page, which may not be desirable. I could pull it off with the Collapsiblock module instead.

aDarkling’s picture

Bootstrap 7.x-3.4 with Bootstrap 3.3.5
Problem still exists. The fix in #34 worked for me!

Andru’s picture

Bootstrap 7.x-3.4 with Bootstrap 3.3.5, Drupal 7.41, Jquery set to 1.7 then also tried 1.10 - same problem. I noticed that the anchor tags used to toggle the collapsibles are not being output as anchors, just spans. Also noticed that the 3.4 version says it wants Jquery 2.1, but Jquery Update does not offer that version yet.
None of the fixes on this page worked for me.

g089h515r806’s picture

I have the same issue. #34 does not work.

g089h515r806’s picture

It is a bug of jquery update module for my case.
https://www.drupal.org/node/2695079#comment-11046745.
Apply this patch fix my issue.

kopeboy’s picture

@arthur_drupal
Where to put this?

/*
 * Implements of hook_js_alter
 */
function HOOK_js_alter(&$js) {
  unset($js['misc/collapse.js']);
}

@g089h515r806
That didn't fix for me. Maybe you did both that and this #34 patch?!

How is this Closed (fixed)?!

I am using bootstrap 7.x-3.5 with jsDelivered bootstrap 3.3.5 (also tried 3.3.6 with no luck), jQuery update to 1.10 and Alternate = Default (provided by Drupal)

See #2755911: Fieldsets in forms not rendered in bootstrap theme if you want to keep this closed..

dozer55’s picture

I have a project where I just discovered this was an issue. After trying several of the aforementioned solutions, I was unsuccessful. For now, I am doing this:

jQuery(document).ready(function(){
  jQuery(".question").click(function(){
    jQuery(this).children(".fieldset-wrapper").toggle();
  });
});

The "question" class that I am targeting comes from the type of view I've built, a "Question" and "Answer" view that the user can toggle the answer on and off. You can edit your code as needed. It's maybe not the cleanest solution, but it works for me!

kopeboy’s picture

Status: Closed (fixed) » Needs review

Guys, just to be clear, what is the result of this problem:

  1. you dont have collapsible behaviour, or
  2. you dont see the fieldset at all (i.e. is not in the HTML)?!

Cause I am having the second problem, and I am surprised such few people are reporting this..

Example:
Commerce Checkout don't get output at all!
Just switch theme and you see everything as normal..

markhalliwell’s picture

Status: Needs review » Closed (fixed)

This issue has become a "catch all" for anything semi-related to fieldsets and #collapsible.

Closing the issue. If you feel something is related, please don't re-open a long closed issue.

Instead, use the "Related issues" field and reference the closed one. That is what it is there for.

m.stenta’s picture