<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Blah Blah Woof Woof comments on Sortable objects in script.aculo.us</title>
    <link>http://vault.openmonkey.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Blah Blah Woof Woof comments</description>
    <item>
      <title>"Sortable objects in script.aculo.us" by triley</title>
      <description>&lt;p&gt;There are some &lt;a href="http://pragmaticprogrammer.com/titles/rails/index.html"&gt;really&lt;/a&gt; &lt;a href="http://pragmaticprogrammer.com/titles/fr_rr/index.html"&gt;good&lt;/a&gt; pieces of Rails documentation popping up around the place these days, but as helpful as they are, it doesn&amp;#8217;t mean you aren&amp;#8217;t ever without enough rope to shoot yourself in the foot.&lt;/p&gt;


	&lt;p&gt;The &lt;a href="http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M000444"&gt;&lt;code&gt;sortable_element&lt;/code&gt;&lt;/a&gt; JavaScript helper makes it really simple to use &lt;a href="http://script.aculo.us/"&gt;script.aculo.us&amp;#8217;&lt;/a&gt; &lt;code&gt;Sortable&lt;/code&gt; object to make lists of items that are sortable using drag and drop.  However, despite the presence of the Rails helper method, it still pays to take careful note of the script.aculo.us&amp;#8217; &lt;a href="http://wiki.script.aculo.us/scriptaculous/show/Sortables"&gt;API documentation&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;In this case, I was wondering why the callback for my sortable list was not being invoked after a drop was completed.  I referred to some examples in the above-mentioned Rails books and I didn&amp;#8217;t seem to be doing anything different at all.  In the end I discovered that a certain format for the &lt;code&gt;id&lt;/code&gt; attributes of your sortable elements is necessary for the list to operate properly and the callback to be invoked:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
 &amp;lt;ul id="sortable-list"&amp;gt;
   &amp;lt;li id="item_1"&amp;gt;First Item&amp;lt;/li&amp;gt;
   &amp;lt;li id="item_2"&amp;gt;Second Item&amp;lt;/li&amp;gt;
 &amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The &lt;code&gt;id&lt;/code&gt; attributes for the list items must contain a &lt;strong&gt;string&lt;/strong&gt;, followed by an &lt;strong&gt;underscore&lt;/strong&gt;, followed by an &lt;strong&gt;integer&lt;/strong&gt;.  I had been using an additional underscore in my string, which caused the list to break.  This wasn&amp;#8217;t mentioned explicitly in any of the books.  So, extra research can never hurt you in the end!&lt;/p&gt;

</description>
      <pubDate>Thu, 16 Mar 2006 21:18:00 PST</pubDate>
      <guid>&lt;a href="/articles/2006/03/16/sortable-objects-in-scriptaculous"&gt;Sortable objects in script.aculo.us&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2006/03/16/sortable-objects-in-scriptaculous"&gt;Sortable objects in script.aculo.us&lt;/a&gt;</link>
    </item>
  </channel>
</rss>

