"Crafting a dynamic multi-level accordion using Twitter Bootstrap and implementing jQueryUI sorting

When dropping the first-level group "Group #2" element into the sub-level group list, it causes the parent accordion to collapse. How can this issue be resolved?

View Demo on jsFiddle

$(document).ready(function() {

// Append icon-plus for all headings
$('.accordion-heading').prepend('<i class="ui-icon ui-icon-triangle-1-e"></i>');

// Change indicator element for sub-menu
$('.accordion-body').on('show', function(e) {
    e.stopPropagation();
   $(this).siblings('.accordion-heading').children('.ui-icon').removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
});
// Reverse it
$('.accordion-body').on('hide', function(e) {
    e.stopPropagation();
   $(this).siblings('.accordion-heading').children('.ui-icon').removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
});

// Make tabs sortable
$(".accordion-body > .accordion, .sidebar").sortable({
                connectWith: ".accordion",
                placeholder: "ui-state-highlight"
});

});

HTML

<nav class="accordion1 accordion sidebar">

    <div class="accordion-group">
        <div class="accordion-heading">
            <a data-toggle="collapse" data-parent=".accordion2" href=".collapse-one">
                Group #1 </a>
        </div>
        <div class="collapse-one accordion-body collapse" style="height: 0px;">
...
                <div class="accordion2 accordion">
                    <div class="accordion-group">
                        <div class="accordion-heading">
                            <a data-toggle="collapse" data-parent=".accordion2" href=".collapse-one-one">
                                Sub-group #1 </a>
                        </div>
                        <div class="collapse-one-one accordion-body collapse" style="height: 0px;">
...
                        </div>
                    </div>
                    <div class="accordion-group">
                        <div class="accordion-heading">
                            <a data-toggle="collapse" data-parent=".accordion2" href=".collapse-one-two">
                                Sub-group #2 </a>
                        </div>
                        <div class="collapse-one-two accordion-body collapse" style="height: 0px;">
...
                        </div>
                    </div>
                    <div class="accordion-group">
                        <div class="accordion-heading">
                            <a data-toggle="collapse" data-parent=".accordion2" href=".collapse-one-three">
                                Sub-Group #3 </a>
                        </div>
                        <div class="collapse-one-three accordion-body collapse">
...
                        </div>
                    </div>
                </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a data-toggle="collapse" data-parent=".accordion1" href=".collapse-two">
                Group #2 </a>
        </div>
        <div class="collapse-two accordion-body collapse" style="height: 0px;">
...
        </div>
    </div>

Answer №1

When the collapsing and expanding events occur upon loading, they impact the same elements even after being rearranged.
It is unclear whether twitter-bootstrap allows for overriding these events and resetting the elements that require collapsing and expanding. If not possible, perhaps it's worth considering extending their version.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Have we considered implementing Number.isNumeric or Function.isFunction instead?

In the realm of JavaScript, a language known for its weak typing system, there are instances where data type validation becomes essential. Many node packages currently rely on helper functions such as isNumber and isFunction. It would be intriguing to hav ...

AngularJS UI Select with StartsWith Searching Feature

I'm currently working on an AngularJS application where I have implemented UI Select. Below is the HTML code snippet: <ui-select name="service" multiple ng-model="service.ServiceName" close-on-select="false" > <ui-select-matc ...

EaselJS BitmapAnimation has delay when using gotoAndPlay

I have created a requirejs module that enhances the functionality of a BitmapAnimation by allowing it to move around the stage at a specific speed and transition to another looped animation once reaching its destination. The issue I am encountering is a n ...

Is it possible to use a server action in Next.js to both retrieve data and refresh the page?

I am currently working on developing a web application using Next.js (13.4.9) and I intend to utilize server actions. These server actions will involve sending data to the server, which will process the data and return a string back to me. The challenge I& ...

What is the purpose of calling Array.prototype.slice on an array with 0 as the starting index?

While exploring the inner workings of Sizzle, I stumbled upon this particular line of code: array = Array.prototype.slice.call( array, 0 ); Upon researching the function, it seems like all it does is return every element in the array starting from index ...

Error: React Component not rendering correctly - Element Type Invalid

React Uncaught Error: Element type is invalid Encountering a problem in my React application where the following error message appears: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite compone ...

Warning: Promise rejection not caught in _.map function in NodeJs

Every time I run the code snippet below, I encounter an error - UnhandledPromiseRejectionWarning: Unhandled promise rejection. This issue is caused by either throwing inside an async function without a catch block or rejecting a promise without handling it ...

React UseEffect does not trigger update upon deletion of data from array

I've hit a roadblock and need some assistance. I'm working on a MERN stack application that interacts with the Github API. Users can search for Github users, save them to their profile on the app, and automatically start following them on Github. ...

Controlling height without using absolute positioning in a multi-step form

Currently, I am using the following script: Is there a way to wrap a multiple step webform in a container without issues with height and absolute positioning? Some of the steps have different heights, and with absolute positioning, having a wrapper with a ...

Leveraging jQuery's element objects and the :contains selector allows for powerful

I need to search for a link that contains the word 'gathered'. Although I understand how to do it logically, I am having trouble writing the jQuery syntax for the selector: if (index === 3) { var $link = $('#rest').find('.tr ...

Tips for combining grid and flex layout to increase the size of a specific flex item

My dashboard at home consists of various independent components with different design structures. Some are managed using CSS Grid, some using CSS Flexbox, and others as default blocks. I am looking to rearrange these components so they stack on top of eac ...

Display or conceal elements by utilizing ng-show/ng-hide according to specific conditions

Here is the code snippet I am working with: <input class="form-field form-control" type="text" name="Website" ng-model="vm.infodata.Website" placeholder="Website Address" maxlength="50" required ng-pattern="/^(www\.)?[a-zA-Z0-9_&bs ...

Difficulty occurred when trying to import Polymer components

Currently, I am in the process of learning how to utilize Polymer. I meticulously followed the instructions provided exactly as specified here. However, upon reaching step 3 and adding the import for paper-checkbox, an error presented itself: Error: A c ...

Activate a commandButton action using a JavaScript-passed variable in JSF

I want to perform an Ajax call from my .xhtml page to my ManagedBean function. Here is the code snippet of what I am trying to achieve: .xhtml form code <h:form id = "jsfform"> <h:commandButton id="button" action="#{c ...

Can someone share tips on creating a stylish vertical-loading progress bar with a circular design?

Currently, I am working on developing a unique progress bar that resembles a glass orb filling up with liquid. However, due to its rounded shape, the traditional approach of adjusting the height does not produce the desired result (as illustrated in this f ...

The highcharts datetime format is not functioning properly within a Bootstrap 4 column

I am using highcharts to display a datetime chart within a Bootstrap 4 column like the example below: HTML: <section> <div class="container"> <div class="row"> <div class="col-md-8"> ...

Utilize Vue: Bring in the router within a helper class and navigate to a specific

I'm new to utilizing Vue, and I am currently attempting to import my existing router instance into a JavaScript class where I manage the Authentication. This is the content of my router file: import Vue from 'vue'; import Router from &apos ...

Iterating through an array with the .forEach method to update all items simultaneously instead of updating each item

I have created a small exercise for my students where I am automating a 10 pin bowling game. You can find it on JsBin here https://jsbin.com/qilizo/edit?html,js,output. However, I seem to be facing some confusion. When I prompt the user to set up the numbe ...

JavaScript implementation causing Safari to display a blank page

After diving into JavaScript recently, I encountered some issues right away. I've been attempting to run a simple "Hello World" program but no success so far. Each time I open the html file in Safari, it displays only a blank page. Despite having enab ...

The iframe does not load within the jQuery dialog

Take a look at this code snippet: <div id="dialog"> <iframe id="myIframe" src=""></iframe> </div> <style> #myIframe{ width: 100%; height: 100%; } </style> function showSet ...