- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Assign column-specific classes $('table.subquestion-list tr', thisQuestion).each(function(i) { $('> *:gt(0)', this).each(function(i){ $(this).addClass('column-'+(i+1)); $(this).attr('data-column', i+1); }); }); // Hide the text inputs in columns 1 and 4 $('.column-1 input[type="text"]', thisQuestion).hide(); $('.column-2 input[type="text"]', thisQuestion).hide(); $('.column-3 input[type="text"]', thisQuestion).hide(); $('.column-4 input[type="text"]', thisQuestion).hide(); $('.column-5 input[type="text"]', thisQuestion).hide(); $('.column-6 input[type="text"]', thisQuestion).hide(); // Insert the checkboxes into column 1 $('.answer-item.column-1', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); $('.answer-item.column-2', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); $('.answer-item.column-3', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); $('.answer-item.column-4', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); $('.answer-item.column-5', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); $('.answer-item.column-6', thisQuestion).append('<input class="checkbox inserted-checkbox" type="checkbox" />'); // Initial checkbox states (if the question has already been answered) $('.inserted-checkbox', thisQuestion).each(function(i) { if($.trim($(this).closest('td').find('input[type="text"]:eq(0)').val()) == 'Y') { $(this).prop('checked', true); } }); // Listener on the checkboxes (insert "Y" into hidden text input when checked) $('.inserted-checkbox', thisQuestion).change(function() { if($(this).is(':checked')) { $(this).closest('td').find('input[type="text"]').val('Y'); } else { $(this).closest('td').find('input[type="text"]').val(''); } }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qArrayID = {QID}; var qArray = $('#question'+qArrayID); var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)'); // Hide the multi-short-text question $(qMultiText).hide(); $('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" /></th>'); // $('table.questions-list thead tr th.answer-text.inserted-column-label', qArray).css('width','40%'); $('tr.answers-list', qArray).each(function(i) { $(this).append('<td class="answer-item text-item">\ </td>\ '); }); // 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)); }); }); </script><script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Add a question class thisQuestion.addClass('custom-array'); // Column-specific classes $('table.subquestion-list tr', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i); }); }); }); </script>
<style type="text/css">.custom-array table.subquestion-list col { width: auto !important; } .custom-array table.subquestion-list thead .column-0 { width: 28%; } .custom-array table.subquestion-list thead .column-1 { width: 7%; } .custom-array table.subquestion-list thead .column-2 { width: 7%; } .custom-array table.subquestion-list thead .column-3 { width: 7%; } .custom-array table.subquestion-list thead .column-4 { width: 7%; } .custom-array table.subquestion-list thead .column-5 { width: 7%; } .custom-array table.subquestion-list thead .column-6 { width: 7%; } .custom-array table.subquestion-list thead .column-7 { width: 30%; } </style>