Nested accordions: a guide to sorting by dragging only the data, not the accordions

I am facing an issue with my two lists that can exchange data. In one list, I have accordions where data can be dropped, and these accordions also contain nested accordions allowing for further data dropping. While I am able to drag and drop data between tables and even within nested accordions, the problem arises when I accidentally drag entire accordions.

Below is a screenshot of my webpage:

The goal is to sort items within an accordion without including the sub-accordions they contain. Here are the JQuery functions I am using:

<script>
    $(function () {
        $("#catalog").accordion({ collapsible: true, active: false, autoHeight: false });
        $(".subcatalog").accordion({ collapsible: true, active: false, autoHeight: false });

        $(".SpecificCatalog").sortable({
            connectWith: ".ui-widget-content, .GeneralCatalog", helper: "clone",
            appendTo: "body",
            stop: function (event, ui) {
                console.log(ui.item);
                console.log(ui.item.text());
            }
        });
        $(".ui-widget-content").sortable({
            connectWith: ".SpecificCatalog, .GeneralCatalog", helper: "clone",
            appendTo: "body",
            stop: function (event, ui) {
                console.log(ui.item);
                console.log(ui.item.text());
            }
        });
        $(".GeneralCatalog").sortable({
            connectWith: ".SpecificCatalog, .ui-widget-content", helper: "clone",
            appendTo: "body",
            stop: function (event, ui) {
                console.log(ui.item);
                console.log(ui.item.text());
            }
        });
    });
</script>

Below is the HTML code which dynamically creates the accordions:

<div id="content">
    <div id="ListaCodigos">
        <h2 class="ui-widget-header">CodigoAgrupador</h2>
        <div id="products">
            <div id="catalog">
                @foreach (CodigoAgrupadorCuentas_CE c in Model.CodigosAgrupadores)
                {
                    if (unchecked(double.Parse(c.CodigoAgrupador) == (int)double.Parse(c.CodigoAgrupador)))
                    {
                        <h3><a href="#">@c.CodigoAgrupador  -  @c.NombreCuenta</a></h3>
                        <div>
                            <div class="subcatalog">
                                @foreach (CodigoAgrupadorCuentas_CE c2 in Model.CodigosAgrupadores)
                                {
                                    if (double.Parse(c2.CodigoAgrupador) > double.Parse(c.CodigoAgrupador) && double.Parse(c2.CodigoAgrupador) < (double.Parse(c.CodigoAgrupador) + 1))
                                    {
                                        <h4><a href="#">@c2.CodigoAgrupador  -  @c2.NombreCuenta</a></h4>
                                        <div>
                                            <div class="SpecificCatalog">
                                                <ol>
                                                    <li class="placeholder">Add your items here</li>
                                                </ol>
                                            </div>
                                        </div>
                                    }
                                }
                            </div>
                            <div class="GeneralCatalog">
                                <ol>
                                    <li class="placeholder">Add your items here</li>
                                </ol>
                            </div>
                        </div>
                    }
                }
            </div>
        </div>
    </div>
    <div id="cart">
        <h2 class="ui-widget-header">Catalogos</h2>
        <div class="ui-widget-content">
            @foreach (LedgerChartOfAccounts c in Model.Catalogos)
            {
                if (c.CodigoAgrupador == null)
                {
                    <ul>
                        <li class="draggable">@c.GLAccountNumber  - @c.GLAccountName  </li>
                    </ul>
                }
            }
        </div>
    </div>
    <div>
        <footer>Insert catalogos into their respective group by dragging.</footer>
    </div>
</div>

I have attempted creating different divisions with unique classes or separators to make the sorting work as intended while keeping the format consistent. However, I am still unable to achieve the desired functionality. Any suggestions would be greatly appreciated.

EDIT: After some exploration, I believe utilizing various classes and separators within the divs is crucial to achieving the desired result. I am struggling to maintain the current format while ensuring proper functionality with the accordions.

Answer №1

After a restful night's sleep and a thorough review of the code, I finally cracked it. The culprit all along was this pesky class: ".ui-widget-content."

It turns out that by utilizing this class in my jquery function connection, I inadvertently made everything within any accordion sortable. This caused numerous "bugs" and "glitches," despite my efforts to separate elements using multiple div classes.

In my revised list, I swapped out the div class from

<div id="ui-widget-content">

to

<div id="codigosAgrupadores>

and adjusted the code in the jquery function accordingly to accommodate the changes.

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

Solve the AJAX Pagination problem by including the 'active' class

Whenever I click on a page number, I want to add an active class. However, the class disappears when an ajax call loads the page. I have tried several methods to solve this issue, but none of them have worked so far. Do you have any suggestions on how I ...

Pictures failing to appear in css/jquery slider

I have a total of 12 divs that are configured to display a thumbnail along with some text dynamically retrieved from a database query. When displayed individually, they appear fine in a column format with a border around them showcasing the thumbnail and t ...

Using Javascript and jQuery to locate and remove a specific value from an array within the remaining values of the

Seeking assistance with organizing array values that may contain duplicated or appended strings. Each value could potentially build upon the previous one. For example: [0] => This is a string. [1] => here's another string. This is a string. [2 ...

Determine the frequency at which a function is invoked, using varying parameters

One of my functions accepts an integer as a parameter: function addToCart(id){ var cart= cart.info; for( i = 0; i < cart.length; i++){ // SOME CODE } } The ID received by the addToCart function corresponds to various items in the s ...

Change the div element to a different div element as the window size is adjusted

Here is the HTML snippet I am dealing with: <div id="div_top"></div> <div id="div_bottom"></div> When viewing the website on a mobile device or resizing the window, I need div_bottom to appear before div_top. To achieve this, I h ...

Enabling the use of jQuery with Angular instead of JQLite

According to the angular DOCS, if jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, angular.element delegates to AngularJS's built-in subset of jQuery, known as "jQuery lite" or jqLite. In an attemp ...

Does anyone know a method for aligning two websites next to each other on one webpage?

As someone with no prior programming knowledge, I took matters into my own hands when I couldn't find what I was looking for. My goal is to integrate two websites into a single webpage, each taking up half of the screen so I can easily switch between ...

Tips for finding information within a table using HTML

My task involves creating a table with the option for users to search data within it. However, I have encountered an issue where I am only able to search for data in the first row of the table. <table style="width:100%" id="table"> <tr> ...

How can I eliminate text using regular expressions?

Greetings, I am seeking assistance with content removal using regular expressions. Below is the regular expression code I have written: reg = reg.replace(/\|.*?(\|)/g, ''); Input: One-1|two-2|Three-3|Four-4|Five-5 Six-6|Seven-7|Eig ...

Using JQuery to delete an item by clicking on the delete button and then clicking on the item to remove it

I am currently using jQuery to dynamically create items on an HTML canvas for users to drag around and create drawings in a style similar to Microsoft Visio. However, I am struggling with how to remove these items once they have been created. While I know ...

Attempting to create a button that will only appear for items with a defined value for a specific variable

I am currently facing an issue with a template that needs proper population. The store locator on my website lists pharmacies and displays their relevant information (phone number, address, hours of operation) along with three buttons (view store, view fl ...

running a loop with a data-attribute conditional statement causes the browser to crash

Currently, I am working on a code snippet that involves hiding elements if the data attribute of a clicked link does not match the data attribute of a specific section. My approach is to iterate through the title elements that do not match the data attribu ...

Position the navigation layer on top of the text

Having an issue here Trying to make the website responsive and encountered a problem where the paragraph ( and the World's Biggest University Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget iaculis dui, quis dapibus diam. Etia ...

How can I overlay text on a background image smoothly?

Currently, I am in the process of developing a website optimized for mobile devices utilizing jQuery Mobile, HTML, and CSS. After successfully setting a background image, I encountered an issue regarding its stability while scrolling. Although the "backg ...

Issue with Scrollspy Functionality in Bootstrap 4

Scrollspy feature isn't working in my code. <nav class="navbar navbar-expand-lg fixed-top navbar-dark" role="navigation"> <div class="container"> <a class="navbar-brand" href="#featured"><h1></h1></a> < ...

Text above a link that is absolutely positioned on a webpage while using Internet

After creating a list of clickable boxes with text inside, an issue arose in IE where the text appears above the link, causing the link to become unresponsive when hovered over. Chrome and Firefox function correctly. I am seeking a solution for this probl ...

Slow rotation in CSS styling

.badge { -webkit-transform-style: preserve-3d; -webkit-perspective: 1000; position: relative; } .back, .front { position: absolute; -webkit-backface-visibility: hidden; -webkit-transition: -webkit-transform 1s ease-in; width: ...

Utilizing JavaScript to dynamically set the height and width of a canvas based on the user input

How can I take user input for height and width values and apply them to a newly created canvas? I am able to retrieve the values, but I'm unsure how to set them as the style.height and style.width properties. var createNewCanvas = document.getEleme ...

What could be causing Bootstrap to shift the final column to a new row?

Without any CSS applied to the table and no modifications made to the row class, consider the code snippet below: <div class="row"> <div class="itemGrid"> <div class="col-xs-1"></div> <div class="col"> ...

Despite using preventDefault and returning false, the user is still being redirected after submitting the form

I'm in the process of trying to send a form using JQuery's .ajax function without having the user redirected upon submission. The form and backend code are both functioning as expected. However, I am encountering an issue when it comes to prevent ...