Avatar of ScottNL1
ScottNL1
 asked on

jquery ui draggable/droppable/sortable

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 ?
JavaScriptWeb Languages and StandardsHTMLScripting Languages

Avatar of undefined
Last Comment
ScottNL1

8/22/2022 - Mon
ScottNL1

ASKER
Nobody have any idea?
ASKER CERTIFIED SOLUTION
Rob

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rob

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
ScottNL1

ASKER
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?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck