Welcome to the LimeSurvey Community Forum

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

Random order is the same for all questions

  • echevalier
  • echevalier's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 1 week ago - 11 months 6 days ago #241587 by echevalier
Random order is the same for all questions was created by echevalier
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.6.8+230227
Own server
Survey theme/template: Inherit [fruity]
==================
Hello,

I am currently creating a questionnaire containing one group with 18 array questions, with each question containing 6 (identical) subquestions. The subquestions should be presented in a random order for each question. The survey is displayed question by question to the participant. I therefore set the "Random order" Display option to "Yes". When I am previewing the question group, each question gets indeed an individual random subquestion order. This is not the case when activating the survey: in this case, the subquestions are randomly shuffled once, but this order is used for every question in the group. I tested the survey on Chrome and Firefox, the issue appeared on both.


The closest topic I found is this one : forums.limesurvey.org/forum/can-i-do-thi...s-in-array-by-column I did not try this solution due to the old age of the topic (5 years) - it seems like random order was not implemented on LimeSurvey on that version yet.

Is there a way to make sure the subquestions get reshuffled for each question? Is there another option I am missing?

Thank you very much, any help is appreciated!

Workaround
The JS code snippet from the old thread mentioned above fixes the problem. You'll need to copy the code below in the question text (using the "Source" editor).

Link: forums.limesurvey.org/forum/can-i-do-thi...ray-by-column#158346


Code:
Code:
<script type="text/javascript" charset="utf-8">
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
 
$(document).on('ready pjax:complete',function() {
 
var thisQuestion = $('#question{QID}');
 
var elements = $('tr.answers-list', thisQuestion).detach().toArray();
shuffleArray(elements);
$('tr.answers-list', thisQuestion).remove();
$. each (elements, function(i, el) {
$('table.subquestion-list tbody:eq(0)', thisQuestion).append(el);
});
});
</script>



Credit to tpartner
Last edit: 11 months 6 days ago by echevalier. Reason: format

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #241588 by Joffm
Replied by Joffm on topic Random order is the same for all questions
There was already a thread about this and a bug report
[url] bugs.limesurvey.org/view.php?id=18440 [/url]

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, echevalier

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #241589 by DenisChenu
Replied by DenisChenu on topic Random order is the same for all questions
remember to click on
 
 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.

Please Log in to join the conversation.

  • echevalier
  • echevalier's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 1 week ago #241591 by echevalier
Replied by echevalier on topic Random order is the same for all questions
Hi Denis,

I don't see the "Does this bug affect you?" link. I tried to login on the bug report site, but my account credentials are not working and when I click on "Sign up" it redirects me to my LimeSurvey account page.

Log in anonymously doesn't let me use the "Does this bug affect you?" link either.

How should I proceed? Thank you!
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #241594 by DenisChenu
Replied by DenisChenu on topic Random order is the same for all questions

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: echevalier

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #241598 by tpartner
Replied by tpartner on topic Random order is the same for all questions

Workaround...
It looks like the code got messed up by the forum editor.

Code:
<script type="text/javascript" charset="utf-8">
  function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
      var j = Math.floor(Math.random() * (i + 1));
      var temp = array[i];
      array[i] = array[j];
      array[j] = temp;
    }
    return array;
  }
 
  $(document).on('ready pjax:complete',function() {
 
    var thisQuestion = $('#question{QID}');
 
    var elements = $('tr.answers-list', thisQuestion).detach().toArray();
    shuffleArray(elements);
    $('tr.answers-list', thisQuestion).remove();
    $. each (elements, function(i, el) {
      $('table.subquestion-list tbody:eq(0)', thisQuestion).append(el);
    });
  });
</script>

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: DenisChenu, echevalier

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose