Welcome to the LimeSurvey Community Forum

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

Issue with Randomization of Subquestions

  • fautin
  • fautin's Avatar Topic Author
  • Away
  • New Member
  • New Member
More
4 days 5 hours ago #267828 by fautin
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.5.2
Own server or LimeSurvey hosting: own server
Survey theme/template: fruity
==================Hello everyone,I'm experiencing an issue with randomization of the order of subquestions in Arrays when I have two questions with the same number of subquestions. In preview mode, the randomization works as expected, but once the survey is activated, only the first question displays randomized subquestions. The following question retains the same order as the first one instead of randomizing independently.This issue occurs when:
  • The content of the subquestions is different,
  • The subquestion codes are different,
  • The questions are in the same group or in different groups
  • The format is set to either "question by question" or "group by group",
  • The questions are in the same randomization group or not,
  • With different themes (fruity, vanilla)
The only way I have found to restore independent randomization is by having a different number of subquestions for each question.

I realize that this is not the latest version of LimeSurvey, but my institution doesn’t plan an update in the near future, and I’ve reviewed the release notes for subsequent versions without finding any mention of this bug.I've attached an LSS file with a simplified version of the survey to illustrate the issue.Any insights or solutions would be greatly appreciated!Thank you in advance!

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 days 5 hours ago #267829 by holch
Replied by holch on topic Issue with Randomization of Subquestions

The following question retains the same order as the first one instead of randomizing independently.


This is not a bug, but a feature. In some cases it is important to randomize subquestions / answer options, but then have the same order for subsequent iterations of this same question.

So it seems like the Limesurvey developers decided that it would be a good idea to make this default. In my opinion it is not ideal, because others might want to have questions randomized differently each time, but this is the solution for the request that they went for.

I am not aware of a way to "switch this off" though.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 hours 17 minutes ago #267877 by tpartner
Replied by tpartner on topic Issue with Randomization of Subquestions

...only the first question displays randomized subquestions. The following question retains the same order as the first one instead of randomizing independently..

Instead of the question setting, you can use JavaScript to randomize the sub-question order.

1) Place a short-text type question directly after each array question. We will hide these questions and use them to store the randomized sub-question order so the respondent will see the same order when returning to the page/group.

2) Place this script in the source of the array question(s).

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  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:scriptcomplete',function(){
 
        // Identify the questions
        var qID = '{QID}';
        var thisQuestion = $('#question'+qID);    
        var textQuestion = thisQuestion.nextAll('.text-short:eq(0)');
        var textInput = $('input:text.form-control:eq(0)', textQuestion);
 
        // Hide the text question
        textQuestion.hide();
 
        var sqCodes = [];
 
        // First visit
        if($.trim(textInput.val()) == '') {
            // Get all sub-question codes
            $($('tr[id^="javatbd"]', thisQuestion)).each(function(i) {
                sqCodes.push($(this).attr('id').split('X'+qID)[1]);
            });
 
            // Randomize the sub-question codes
            shuffleArray(sqCodes) 
 
            // Load the sub-question codes into the hidden short-text question
            textInput.val(sqCodes)
        }
        // Returning to the page
        else {
            sqCodes = $.trim(textInput.val()).split(',');
        }
 
        // Insert the random sub-questions
        $.each(sqCodes, function(i, sqCode) {
            $($('table.subquestion-list tbody:eq(0)', thisQuestion)).append($('tr[id$="X'+qID+sqCode+'"]', thisQuestion));
 
        });
    });
</script>

Sample survey: 

File Attachment:

File Name: limesurvey...3855.lss
File Size:68 KB

 

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.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose