Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI Sortable and two connected lists
    text
    copied!<p>I am trying to put together the following with jQuery and Sortable: There are two cases that I need to grab:</p> <ul> <li><strong>A:</strong> move an item within the same list</li> <li><strong>B:</strong> move an item from one list to another</li> </ul> <p>Case <strong>B</strong> is solved when only using the <code>receive</code> event. But if I bind both <code>receive</code> and <code>stop</code> they also get fired both when moving an item from one list to another. This makes it impossible for me to capture case <strong>A</strong> because I have no way of finding out if the item was moved from another list or within the same. Hope that makes sense.</p> <p>This is kind of weird because I would think of my use case as being the most used one. </p> <p>I am craving for ideas. If you want to try it out, see <a href="http://jsfiddle.net/39ZvN/5/" rel="noreferrer">http://jsfiddle.net/39ZvN/5/</a>.</p> <p>HTML:</p> <pre><code>&lt;div id="list-A"&gt; &lt;ul class="sortable"&gt; &lt;li&gt;item 1&lt;/li&gt; &lt;li&gt;item 2&lt;/li&gt; &lt;li&gt;item 3&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;br /&gt; &lt;div id="list-B"&gt; &lt;ul class="sortable"&gt; &lt;li&gt;item 4&lt;/li&gt; &lt;li&gt;item 5&lt;/li&gt; &lt;li&gt;item 6&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>JS:</p> <pre><code>$(function() { $('.sortable').sortable({ stop: function(event, ui) { // Wird auch aufgerufen wenn von Liste X nach Liste Y gezogen wird if(!ui.sender) alert("sender null"); else alert("sender not null"); }, receive: function(event, ui) { // Funktioniert top, damit kann ich Fall B abfangen alert("Moved from another list"); }, connectWith: ".sortable" }).disableSelection(); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload