script.aculo.us Ajax Sortable Lists adjustment for ColdFusion
So normally I’m a YUI guy. I enjoy their widgets and some of the other features available, and I’m comfortable with it. I work with several sites here that my co-workers work on, and they often prefer different JS Libraries. So I try to minimize the libraries on a site. Nothing more difficult, I feel, when you’re maintaining a website and have to maintain YUI, jQuery, Dojo, and Script.aculo.us/Prototype all at the same time and with all of those libraries loading for a client!
So I had to repair something that wasn’t working in IE8 (imagine that
) that was written quite some time ago. The site had script.aculo.us/prototype on it so I wanted to stick with that library. Thankfully, I came across this post: http://zenofshen.com/posts/ajax-sortable-lists-tutorial and it’s a pretty handy layout for PHP and Script.aculo.us. The problem arises at the bottom of the post. In PHP, you would be fine using this:
1 | parse_str($_POST['data']); |
ColdFusion won’t parse out the string of list_to_sort[]=2&list_to_sort[]=1&list_to_sort[]=3 like that though. So I recommend making this adjustment to what’s coming through:
1 2 3 4 5 6 7 8 9 10 11 | <cfset newList = ListChangeDelims(url.data, "|", "list_to_sort[]=,&list_to_sort[]=")> <cfset sortPos = listLen(newList, "|")> <cfloop list="#newList#" delimiters="|" index="thisID"> <cfquery name="insertSort" datasource="#request.source#"> INSERT INTO 'table' (listID, sortOrder) VALUES (#thisID#, #sortPos#) </cfquery> <cfset sortPos = sortPos - 1 /> </cfloop> |

