Bootstrap collapse in moodle 4.0 (boost)

Bootstrap collapse in moodle 4.0 (boost)

by Stefan Hanauska -
Number of replies: 11
Picture of Core developers Picture of Plugin developers

Hi everybody!

Yesterday I drafted a small plugin (subplugin to mod_unilabel, https://github.com/sh-csg/moodle-unilabeltype_accordion) to provide an easy way to use Bootstrap accordion. It works well up to moodle 3.11, in moodle 4.0 (with theme boost) I noticed the following behaviour:

Everytime I click to expand / collapse a segment produced by the plugin, the current section is collapsed. This also happens when you use Bootstrap collapse in labels (e.g. the code from https://getbootstrap.com/docs/4.6/components/collapse/ ). The attribute data-target is set in both cases.

Does anybody have an idea how to avoid this? Bootstrap collapse itself doesn't seem to have problems with nested collapse elements.

Thanks a lot for your help!

Stefan


Average of ratings: -
In reply to Stefan Hanauska

Re: Bootstrap collapse in moodle 4.0 (boost)

by Tom Cripps -
Hi Stefan,

We're also having this issue, did you manage to fix it? If so, can you tell me how?

Thank you!
In reply to Tom Cripps

Re: Bootstrap collapse in moodle 4.0 (boost)

by Stefan Hanauska -
Picture of Core developers Picture of Plugin developers
Hi Tom,

Andreas Grabs helped me to solve this problem. See the code at https://github.com/grabs/moodle-mod_unilabel/blob/MOODLE_40_STABLE/type/collapsedtext/templates/collapsed.mustache (from line 57).

Best regards
Stefan
Average of ratings: Useful (1)
In reply to Stefan Hanauska

Re: Bootstrap collapse in moodle 4.0 (boost)

by Tom Cripps -
Thanks Stefan,

This is very helpful, we'll have to apply this to standard Boost somehow as lots of our users like to add accordions on the course pages, this is very helpful at pointing us where to go

Tom
In reply to Tom Cripps

Re: Bootstrap collapse in moodle 4.0 (boost)

by Stefan Hanauska -
Picture of Core developers Picture of Plugin developers

Hi Tom,

maybe using mod_unilabel is also an option for you? It now includes my subplugin for accordion.

Best regards

Stefan

In reply to Stefan Hanauska

Re: Bootstrap collapse in moodle 4.0 (boost)

by Stefan Zimmer -

Hi Tom and Stefan,

since I updated to Moodle 4.0 we also have the issue with the Bootstrap Accordion. When you click on an element of the accordion, the whole area closes. 

Do you have any idea how I can turn off this behavior? I would prefer to work with additional CSS code. I don't necessarily want to change anything in the source code of Moodle, as there will be more work in future updates. 

Greetings from Hamburg

Stefan

In reply to Stefan Zimmer

Re: Bootstrap collapse in moodle 4.0 (boost)

by Tom Cripps -
We didn't resolve this unfortunatley, we've advised users not to place accordions in the course homepage, but we've had moodle a number of years and encouraged the use of bootstrap components so this is not going to be a viable solution for us.

We have added a stop gap to 'force' open the accordion so it's always showing all content - this is also not a solution just a stopgap so our users don't have to remove content from accordions. This would not go down well!
In reply to Tom Cripps

Re: Bootstrap collapse in moodle 4.0 (boost)

by Stefan Zimmer -

Hey Tom, 

thanks for your answer. That sounds like a reasonable interim solution. How exactly did you implement it? Maybe we'll integrate that into ours as well. 

Many greetings

Stefan

In reply to Stefan Zimmer

Re: Bootstrap collapse in moodle 4.0 (boost)

by Tom Cripps -

Hi Stefan,

We added the following to the the css (not javascript as I originally said) in our theme:


#page-course-view-weeks .modtype_label .collapse:not(.show) { display: block !important; }
#page-course-view-topics .modtype_label .collapse:not(.show) { display: block !important; }


This will target accordions in labels in both the week and topic course formats

It's not the best solution but hopefully this helps for now, I'll let you know if we come up with a better fix.

In reply to Tom Cripps

Re: Bootstrap collapse in moodle 4.0 (boost)

by Stefan Zimmer -

Hey Tom,

thanks for your answer! That's a good workaround. Hopefully the moodle developers will find a solution for bootstrap soon... 


In reply to Stefan Zimmer

Re: Bootstrap collapse in moodle 4.0 (boost)

by Luca Bösch -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Do you have a link to an existing MDL- issue in tracker, Stefan?
Otherwise, please perform a search, and in case there isn't one, create one.
That increases the chances to be taken on and solved significantly!