- Posts: 14
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>