# Reorder lists only after clicking link

**URL:** <https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032>\
**Category:** Rails\
**Created:** [July 26, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032 "2006-07-26T20:05:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scoobycoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scoobycoder](https://www.ruby-forum.com/u/scoobycoder)\
**Post date:** [July 26, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032/1 "2006-07-26T20:05:12Z")

</div>

Yo,

I have created the usual list that uses drag and drop to reorder stuff  
and it all works fine. But I don’t want the list to be draggable until  
someone clicks a button (or link) to enable the reordering.

My only idea so far is to have the drag handles hidden with javascript  
and the show them onclick, but this is messy. Is there not a clean way  
to do this?

## Is there a way to uncreate a sortables list? (the opposite of the method that creates them. that would solve the problem I think.)

://  
Nathan H.

---

<div class="post-metadata">

**Author:** ![scoobycoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scoobycoder](https://www.ruby-forum.com/u/scoobycoder)\
**Post date:** [July 26, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032/2 "2006-07-26T23:27:14Z")

</div>

Nathan H. wrote:

> Yo,
> 
> I have created the usual list that uses drag and drop to reorder stuff  
> and it all works fine. But I don’t want the list to be draggable until  
> someone clicks a button (or link) to enable the reordering.
> 
> My only idea so far is to have the drag handles hidden with javascript  
> and the show them onclick, but this is messy. Is there not a clean way  
> to do this?
> 
> ## Is there a way to uncreate a sortables list? (the opposite of the method that creates them. that would solve the problem I think.)
> 
> ://  
> Nathan H.

\<%= link\_to\_function(‘enable sorting’,  
“#{sortable(…)} $(‘mylist’).className=‘sortable’”) %\>

Then hide the handles via CSS so they have a “display:hidden” without  
the class “sortable” on the parent container, and a “display:inline”  
when the class is defined. This way you dont need to iterate though  
each handle and show it.

To uncreate the sortable I think you have to overwrite it with a fresh  
copy. So in the RJS response for disabling the sorting you can replace  
the list with a partial. I’m mostly sure that will remove the sorting  
until sortable is called again.

---

<div class="post-metadata">

**Author:** ![scoobycoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scoobycoder](https://www.ruby-forum.com/u/scoobycoder)\
**Post date:** [July 27, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032/3 "2006-07-27T17:14:27Z")

</div>

On 2006-07-26 17:27:14 -0400, Alex W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> the list with a partial. I’m mostly sure that will remove the sorting  
> until sortable is called again.

I like the idea of doing the class name thing to hide the sortables.

The Sortable.destroy() method works, but I have to create a toggle  
function to test to see if it needs destroying. I like this better than  
reloading the content, just because it doesn’t hit the server.

## Is there a way to write RJS code that can just be loaded in with the :defaults set of javascript files and not after a call to a controller?

://  
Nathan H.

---

<div class="post-metadata">

**Author:** ![scoobycoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scoobycoder](https://www.ruby-forum.com/u/scoobycoder)\
**Post date:** [July 27, 2006, 12:03pm UTC](https://www.ruby-forum.com/t/reorder-lists-only-after-clicking-link/100032/4 "2006-07-27T12:03:44Z")

</div>

On 2006-07-26 10:19:11 -0400, Nathan H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> Is there a way to uncreate a sortables list? (the opposite of the  
> method that creates them. that would solve the problem I think.)

There is a javascript way to do it, Sortable.destroy, but I loose all  
the rails goodness by declairing the oncomplete myself.

In RJS, I can use page.sortable, but it does not behave like it is  
documented. [Script.aculo.us](http://Script.aculo.us) says that if you create a sortable on an  
already existing one, it destroys it. This does not happen.

What I really need is a way to do if statements in RJS.

I want to say:

if page[‘thing’].innerHTML == ‘something’  
page.sortable ‘things\_owner’  
page.replace\_html ‘thing’, ‘not something’  
else  
page \<\< "Sortable.destroy(‘things\_owner’)  
page.replace\_html ‘thing’, ‘something’  
end

I wish it was that easy…or easier.

I just wrote the whole crap thing in javascript for now, which is not  
pretty at all.

## Please, any ideas?

://  
Nathan H.
