views:

195

answers:

2

I have 2 connected sortable lists. One is inside an accordion. When I try to drag items from the sortable in the accordion, the helper disappears as soon as I get outside of the accordion. I can drop to one of the other connected sortables and the item will display, but it just doesn't display while I'm dragging. The accordion also scrolls down if I drag and item down.

I can drag & drop items from either of the other list wherever I need and it works fine. How can I make items not disappear while dragging them from inside an accordion to the outside of it?

I've already tried the containment option but that seems to have no effect.

Here's code to expose the problem that I've taken from these examples: http://jqueryui.com/demos/sortable/#connect-lists

I want to be able to drag items from the accordion into the sortable list. I can actually drop them into the list, but they disappear while I'm dragging them outside of the accordion.

<html>
<head>

<title>Accordion Sortable Failure Test</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
$(function(){
    $(".sortable").sortable({connectWith: ".sortable"});
    $("#accordion").accordion({ header: "h3" });
});
</script>

</head>

<body>

<h2>Sortable</h2>
<ul class="sortable">
    <li>Row 1</li>
    <li>Row 2</li>
</ul>

<h2>Accordion</h2>
<div id="accordion">
    <div>
        <h3><a href="#">First</a></h3>
        <ul class="sortable">
            <li>Lorem</li>
            <li>ipsum</li>
            <li>dolor</li>
        </ul>
    </div>
    <div>
        <h3><a href="#">Second</a></h3>
        <div>Phasellus mattis tincidunt nibh.</div>
    </div>
    <div>
        <h3><a href="#">Third</a></h3>
        <div>Nam dui erat, auctor a, dignissim quis.</div>
    </div>
</div>

</body>
</html>
A: 

paste a sample of your code so we know what you have left out... it seems that while you are on mouse down... then your accordion fires an event... i could be wrong but sounds like it... so try and have a look at propagation and stopPropagation on jquery.

Val
I added source code. Can you suggest or link to how to identify which event on which element may have had propagation stopped?
Matt
please look at this: http://jqueryui.com/demos/accordion/#sortable should help with your thing if you want accordio to be sortable itself. other wise on the sortable ui you should have a look at helper. e.g. `helper:'clone'` so add the following ` $(".sortable").sortable({connectWith: ".sortable",helper: 'clone'});` this will show a clone of the element you are dragging while dragging is fired then when finished destroys the clone, keeps the original on the drop target
Val
A: 

I'm a little late, I know, but I had a similar problem with two sortable accordions where you can drag&drop items between the two accordions.

So, for future reference:

I also couldn't get the accordion-items to "go out" of the source-accordion, and google led me to this question.

I solved my problem by adding axis: undefined on the sortable() function:

        $("#accordion1")
        .accordion({
            collapsible: true,
            header: "> div > h3",
            dropOnEmpty: true,
            autoHeight: false,
            active: false
        })
        .sortable({
            axis: "y",
            handle: "h3",
            stop: function() {
                stop1 = true;
            },
            connectWith: '.connectedSortable',
            helper: 'clone',
            axis: undefined
        });

Now the accordion-items can be dragged all over the place.

Frank Hansen