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
  • Offline
  • New Member
  • New Member
More
1 month 1 week 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
1 month 1 week 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.

The following user(s) said Thank You: fautin

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 1 week 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.
The following user(s) said Thank You: fautin

Please Log in to join the conversation.

  • fautin
  • fautin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 6 days ago - 1 month 6 days ago #267903 by fautin
Replied by fautin on topic Issue with Randomization of Subquestions
Thank you both for your replies, and thanks a lot for the workaround. I haven’t been able to try it yet, as I currently don’t have permissions to disable the XSS filter (though I’ve requested this from my institution).

I’m still confused as to why LimeSurvey treats these questions as different iterations of the same question, given that everything about them differs (codes, content) except for the type and number of sub-questions ; and as to why randomization is independent when I preview the survey.
I’m asking to understand this better and to see if there might be another possible workaround.
Last edit: 1 month 6 days ago by fautin.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 6 days ago #267914 by Joffm
Replied by Joffm on topic Issue with Randomization of Subquestions
Hi,

In my opinion, this feature is really useful.
Usually clients require that an initial randomizatuion of a certain list is kept .
If I display a randomized list of car brands and
the first respondent sees "FIAT", "Alfa Romeo", "Volvo", "Ford" he should see always this order.
and the next respondent sees "Volvo", "Ford", "Alfa Romeo", "FIAT"

Otherwise respondents would get confused and maybe complain about this stupid developer of the questionnaire.

I’m asking to understand this better and to see if there might be another possible workaround.

In this case you should have a look at the source code.
We - the volunteers of the forum - do not have much insight, as long as we do not investigate ourselves.

and as to why randomization is independent when I preview the survey.

You see, only in an active survey there is a record in the database where the "seed" is stored.

Joffm


 

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

Please Log in to join the conversation.

  • fautin
  • fautin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 5 days ago - 1 month 5 days ago #267930 by fautin
Replied by fautin on topic Issue with Randomization of Subquestions
Thank you all for your help and suggestions! I really appreciate the time you took to explain things and assist me. Unfortunately, I won’t have the necessary permissions to use the code you provided in my survey...

However, I wanted to share a workaround I found based on that:  #256794 , in case it helps others with a similar issue. Here’s what I did:

1. I created a hidden multiple-choice question (HM) where the subquestions codes correspond those of the following array questions.
2. and a hidden equation type question to set which subquestions should be displayed ({HM_1="Y"} {HM_2="Y"} ...)
3. For each array question, I added a different number of extra subquestions that remain hidden.

By doing this, the questions are treated as different by LimeSurvey, and the randomization now works independently for each question.
 
Last edit: 1 month 5 days ago by fautin.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose