I’ve just run into this problem. It seems that the problem is with Sortables.destroy. If you create a sortable within another sortable then this line of dragdrop.js:

    // clear any old sortable with same element

    this.destroy(element);

 

Will actually end up destroying the parent. Put this at the in your code after you include scriptaculous and it should sort it out:

 

Sortable.destroy = function(element){

    var s = Sortable.options(element);

   

    if(s) {

                       

                         if(element.id == s.element.id) { //Modification. Checks destroying correct element.

                                                           

                          Draggables.removeObserver(s.element);

                          s.droppables.each(function(d){ Droppables.remove(d) });

                          s.draggables.invoke('destroy');

                         

                          delete Sortable.sortables[s.element.id];

                         

                        }

    }

  }

 

I’m not sure though if this might have any undesirable knock-on effects….

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Justin McCormack
Sent: 11 July 2006 11:24
To: rails-spinoffs@lists.rubyonrails.org
Subject: [Rails-spinoffs] Scriptaculous Sortable within a Sortable

 

Hi,

Forgive me if this has been discussed/resolved before. I have done a search of both this mailing list and the web, but I can't find a solution to my problem (which is odd as I would think plenty of people would have the same requirement and therefore the same problem).

Basically, I have a OL of "Questions". Each question has an OL of "Answers". The user needs to be able to order the questions and also the answers within each question. Here is some HTML and script that demonstrates the issue:

<ol id="questionList1" class="questionsList">
  <li class="question" id="question1">
    <span class="questionTitle">Question 1</span>
    <ol id="answerList1" class="answersList">
      <li class="answer">Answer 1</li>
      <li class="answer">Answer 2</li>
    </ol>
  </li>
  <li class="question" id="question2">
    <span class="questionTitle">Question 2</span>
    <ol id="answerList2" class="answersList">
      <li class="answer">Answer 1</li>
      <li class="answer">Answer 2</li>
    </ol>
  </li>
</ol>
<script type="text/_javascript_">
    Sortable.create("questionList1", {only: "question", handle: "questionTitle"});
    Sortable.create("answerList1", {only: "answer"});
    Sortable.create("answerList2", {only: "answer"});
</script>

By creating a sortable on the sub OL (answersLists), it stops the main questionsList from being sortable (i.e can't sort questions). If we comment out the Sortable.create for the two answer lists, the main questions sortable works fine.

Am I doing something wrong (obviously)? Is it possible to acheive what I need with Sortables?

Thanks in advance,

Justin

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to