Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Randomise MultiChoice except last few - multi column

  • marcgold
  • marcgold's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
4 years 5 days ago #211667 by marcgold
Can someone help please with a slight variation of the following script.   In single column it works well,  but just noticed that when you split into multi column although the script still has the last 3 at the end they are not always in the last column.   it splits this accros however many columns you have.

This is in LS 3.25.10  
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Define the sub-question codes to be placed last
    var lastItems = ['SQ006', 'SQ007', 'SQ008'];
 
    // Loop through those sub-question codes 
    $.each(lastItems, function(i, val) {
      // Move that item to the end of the list
      // Multi-choice question
      if($(thisQuestion).hasClass('multiple-opt')) {
        $('.question-item[id$=X'+qID+val+']', thisQuestion).appendTo($('.question-item[id$=X'+qID+val+']', thisQuestion).parent());
      }
      // Array question
      if($(thisQuestion).hasClass('array-flexible-row')) {
        $('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list tbody:last', thisQuestion));
      }
      // List-radio question
      if($(thisQuestion).hasClass('list-radio')) {
        $('.answer-item[id$=X'+qID+val+']', thisQuestion).appendTo($('.answer-item[id$=X'+qID+val+']', thisQuestion).parent());
      }
    });  
  });
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 days ago #211686 by tpartner
Can you attach a sample survey (.lss file) containing only one question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • marcgold
  • marcgold's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
4 years 5 days ago #211688 by marcgold
Hi Tony,

Of course, here you go. This is using the Fruity Template. I have switched it to the default one as we use a customised version. Same problem though.

Marc
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 days ago - 4 years 4 days ago #211722 by tpartner
This will handle columns in multiple-choice and list-radio questions:
 
 
Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Define the sub-question/answer codes to be placed last
    var lastItems = ['SQ017', 'SQ018', 'SQ019'];
 
    // Loop through those sub-questio/answer codes 
    $.each(lastItems, function(i, val) {
      // Move that item to the end of the list
      // Multi-choice/single-choice question
      if($(thisQuestion).hasClass('multiple-opt') || $(thisQuestion).hasClass('list-radio')) {
        if($('.multiple-list', thisQuestion).length > 0) {
          var thisItem = $('.answer-item[id$=X'+qID+val+']', thisQuestion);
          var thisList = thisItem.parent();
          thisItem.addClass('inserted-item');
          thisItem.appendTo($('.multiple-list ul:last', thisQuestion));
          $('.answer-item:not(.inserted-item):last', thisQuestion).prependTo(thisList);
        }
        else {
          $('.answer-item[id$=X'+qID+val+']', thisQuestion).appendTo($('.answer-item[id$=X'+qID+val+']', thisQuestion).parent());
        }
      }
      // Array question
      if($(thisQuestion).hasClass('array-flexible-row')) {
        $('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list tbody:last', thisQuestion));
      }
    });  
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...9143.lss
File Size:36 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 4 days ago by tpartner.
The following user(s) said Thank You: Joffm
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose