Welcome to the LimeSurvey Community Forum

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

Keeping one item at the bottom (or end) when randomizing rows or columns

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225879 by eniisula
I have randomized in one question of array numbers checkboxes the rows and I want the last y-scale subquestion to stay at the bottom while others are being randomized. 
Also I have a normal array where I have randomized the answer options with a javascript code but I want the last answer option in this array to stay fixed while others are being randomized. 
Currently I have achieved randomizing the proper rows and columns but I want the last of each options to be fixed.

How can I do this?

Thank you in advance!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225889 by Joffm
I wonder, why you didn't answer the initial questions.
So I do not know if it works in your used version.
I tested in 3.27.33

Here you find a working example
[url] www.limesurvey.org/manual/Workarounds:_M...ime_using_Javascript [/url]

Of course we can't say anything if you did something unexpected as 

I have randomized the answer options with a javascript code

and not used the setting "Random order".



 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225890 by eniisula
For the question that I wanted to randomize the row I used random order option but for the question where I wanted to randomize the columns I used a javascript code I found on the forum and adapted to my code. But I want one of the columns to be fixed at the end while others are randomized with this code.

forums.limesurvey.org/forum/can-i-do-thi...ray-not-subquestions

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225891 by tpartner
Regarding rows - forums.limesurvey.org/forum/can-i-do-thi...-number-fixed#208970

Regarding randomized columns can you attach a small sample survey (.lss file) containing only the relevant question and your code?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225892 by eniisula
For randomizing columns I used this code here where I put it in custom.js and called the function the source code of the question. When I try attaching the survey question the it does not work, maybe because I use a custom theme.
forums.limesurvey.org/forum/can-i-do-thi...ray-not-subquestions

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225893 by tpartner
I asked for a sample survey (.lss file), not a sample question. Sample questions require too much work on the part of the volunteers giving help.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago - 3 years 3 months ago #225895 by eniisula
I hope this attachment is okay for you.

I want the answer option with this code AO07, to stay as the last column while others are being randomized.
Last edit: 3 years 3 months ago by eniisula.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225897 by tpartner
What is your LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225898 by eniisula
Version 5.2.13+220207

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225900 by tpartner
Add this script to the question source, it will randomize answers and fix the answer column with code "AO07" to the end. (adjust the fixedAnswerCode variable as required)

 
Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var fixedAnswerCode = 'AO07';
 
    var thisQuestion = $('#question{QID}');
 
    // Index the array columns
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      $('> *', this).each(function(i) {
        $(this).attr('data-index', i);
      });
    });
 
    // Identify the fixed column
    var fixedIndex = $('.answer_cell_'+fixedAnswerCode+':eq(0)').attr('data-index');
    $('[data-index="'+fixedIndex+'"]', thisQuestion).addClass('fixed-column');
 
    // Identify "no answer"
    if($('.noanswer-item', thisQuestion).length > 0) {
      $('table.subquestion-list tr > :last-child', thisQuestion).addClass('col-no-answer');
    }
 
    // Create an array of the columns
    var columns = [];
    $('table.subquestion-list tr.answers-list:eq(0) td.answer-item', thisQuestion).each(function(i) {
      columns.push($(this).attr('data-index'));
    });  
 
    // A function to shuffle elements or contents of arrays
    (function($){
      $.fn.shuffle = function() {
        return this.each(function(){
          var items = $(this).children();
          return (items.length)
            ? $(this).html($.shuffle(items))
            : this;
        });
      }
 
      $.shuffle = function(arr) {
        for(
          var j, x, i = arr.length; i;
          j = parseInt(Math.random() * i),
          x = arr[--i], arr[i] = arr[j], arr[j] = x
        );
        return arr;
 
      }
    })(jQuery);
 
    // Shuffle the columns array
    columns = $.shuffle(columns);
 
    // Reposition the row elements
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      var thisRow = $(this);
      $(columns).each(function(i, val) {
        thisRow.append($('[data-index="'+val+'"]', thisRow));
        thisRow.append($('.fixed-column', thisRow));
        thisRow.append($('.col-no-answer', thisRow));
      });
    });
  });
</script>

Sample survey attached: 

File Attachment:

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: eniisula

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225902 by eniisula
Thank you so much for this code and for your time. Highly appreciated!

Regards!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose