- Posts: 14
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Randomisation of array with textbox - all in same question group
- Chrisou
- Topic Author
- Offline
- New Member
Less
More
3 years 11 months ago #197794
by Chrisou
Randomisation of array with textbox - all in same question group was created by Chrisou
After getting ample help in
this thread
on how to add a textbox to a basic array, I am now faced with the following problem:
I'd like to randomise my questions, but if I put everything in the same randomisation group, LS will sometimes put two "comment boxes" together to create something like you see attached. If I only randomise the actual questions, they will randomise, but the comments stay in the order I put them in originally.
Is there any way to couple the questions with the comment boxes so they randomise together while they're all in the same question group?
I'd like to randomise my questions, but if I put everything in the same randomisation group, LS will sometimes put two "comment boxes" together to create something like you see attached. If I only randomise the actual questions, they will randomise, but the comments stay in the order I put them in originally.
Is there any way to couple the questions with the comment boxes so they randomise together while they're all in the same question group?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
3 years 11 months ago #197809
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomisation of array with textbox - all in same question group
You will need to randomize the question order with JavaScript after inserting the text elements.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Chrisou
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 1
3 years 11 months ago #197814
by Chrisou
Replied by Chrisou on topic Randomisation of array with textbox - all in same question group
Okay, how do I do that?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
3 years 11 months ago #197816
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomisation of array with textbox - all in same question group
Can you provide a small sample survey (.lss file) containing only the relevant group.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Chrisou
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 1
3 years 11 months ago #197819
by Chrisou
Replied by Chrisou on topic Randomisation of array with textbox - all in same question group
Okay, I hope this works!
It should end up so that "Einstein Question" is paired with "Einstein Comment" and so on, but in random order.
It should end up so that "Einstein Question" is paired with "Einstein Comment" and so on, but in random order.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
3 years 11 months ago - 3 years 11 months ago #197864
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomisation of array with textbox - all in same question group
You will need to aggregate all of the scripts that insert the text elements into a single question, then you can run the randomization script after all questions have been manipulated.
Remove the scripts from all of your array questions and add this aggregated script to the source of the first array question in the group:
Sample survey attached:
Remove the scripts from all of your array questions and add this aggregated script to the source of the first array question in the group:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Define a JS array for the question IDs var idsArr = []; // Loop through all of the array questions $('.array-flexible-row').each(function(i) { // Add this question ID to the JS array idsArr.push($(this).attr('id')); // Identify the questions var qArrayID = $(this).attr('id').replace(/question/, ''); var qArray = $(this); var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)'); // Add some classes qArray.addClass('array-with-uploads-question'); //Hide the multi-short-text question $(qMultiText).hide(); // Insert a new column $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto'); $('table.questions-list thead tr', qArray).append('<th class="answer-text inserted-column-label" />'); $('tr.answers-list', qArray).each(function(i) { $(this).append('<td class="answer-item text-item" />'); }); // Load the column label for the text inputs $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text()); $('.text-item', qArray).append('<label class="ls-label-xs-visibility">'+$('.ls-label-question', qMultiText).text()+'</label>') // Loop through the multi-short-text sub-questions $('li.answer-item', qMultiText).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray)); }); }); // Shuffle the JS array of IDs shuffleArray(idsArr); // Insert the array quesions in the new order $.each(idsArr, function(i, value) { console.log('#'+value); $('.group-container').append($('#'+value)); }); }); 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; } </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 3 years 11 months ago by tpartner.
The following user(s) said Thank You: Chrisou
The topic has been locked.
- Chrisou
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 1
3 years 11 months ago #197887
by Chrisou
Replied by Chrisou on topic Randomisation of array with textbox - all in same question group
Thank you so much, it works perfectly!! :laugh:
The topic has been locked.