Solved

jquery ui draggable/droppable/sortable

Posted on 2012-03-16
6
845 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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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 42

Expert Comment

by:Rob Jurd, EE MVE
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now