Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jquery ui draggable/droppable/sortable

Posted on 2012-03-16
6
Medium Priority
?
864 Views
Last Modified: 2012-03-18
What do i want to do
Drag from 1 <li> copy it and drop it in a <ul> with some rules.


Exampel

Drag this:
<ul class="dragelem">
&#9;<li class="drag-image" ><img src="any image" border="0"  /></li>
&#9;<li class="drag-image" ><img src="any image" border="0"  /></li>
</ul>

Drop here:
<ul id="sortable" class="drop">

</ul>

This seems easy enough by adding this
&#9;$(function() {
&#9;&#9;$( "#sortable" ).sortable({
&#9;&#9;&#9;revert: true
&#9;&#9;});
        $( ".drag-image" ).draggable({
            connectToSortable: "#sortable",
            helper: "clone",
&#9;&#9;&#9;revert: "invalid"
            });
         $( "ul, li" ).disableSelection();
    });

The exceptions:

Maximum number of <li> tags within <ul id= "sortable"> is 5.
If there are 5 and you want to drag a new one to the sortable it should replace the one it has been dropped on.

Haven't been able to find a solution for that yet. Any idea's ?
0
Comment
Question by:ScottNL1
  • 2
  • 2
6 Comments
 
LVL 1

Author Comment

by:ScottNL1
ID: 37730080
Nobody have any idea?
0
 
LVL 43

Accepted Solution

by:
Rob earned 1500 total points
ID: 37732423
Have a look at this:  http://jsfiddle.net/rjurd/U3jW3/

essentially it is about enabled a droppable object on the items you are dragging to the other list box and setting it's drop event to 'greedy' meaning "If true, will prevent event propagation on nested droppables."
0
 
LVL 43

Expert Comment

by:Rob
ID: 37732424
FYI I have only implemented the replace method when it is dropped on another.  I'll leave it up to you to implement the other rules etc though I'm happy to help if you get stuck
0
 
LVL 1

Author Comment

by:ScottNL1
ID: 37732436
Thanks for the input. Run into another problem when using this method. After clone, all items within sortable are deleted when placing one on top if the other. I think i am going to pass on this method and create a delete button if you want to remove items.  

Still stuck with the maximum number of items to place within ul sortable. This is a dynamic number from 1 up to 5.

I was thinking of sticking
getElementsByTagName('li').length  somewhere within the draggable. But where and how?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question