Solved

jquery ui draggable/droppable/sortable

Posted on 2012-03-16
6
856 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

821 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