?
Solved

jquery ui draggable/droppable/sortable

Posted on 2012-03-16
6
Medium Priority
?
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

718 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