- Posts: 4
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<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','30%'); $('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); }); }); // Insert selects $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">Ja</option>\ <option value="2">Nein</option>\ <option value="3">Weiß nicht</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val(); $('select.inserted-select', thisCell).val(selectval); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
<style type="text/css">.custom-array table.subquestion-list col { width: auto !important; } .custom-array table.subquestion-list thead .column-0 { width: 25%; } .custom-array table.subquestion-list thead .column-1 { width: 15%; } .custom-array table.subquestion-list thead .column-2 { width: 60%; } </style>
<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); }); }); // Insert selects $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">...</option>\ <option value="1">Ja</option>\ <option value="2">Nein</option>\ <option value="3">Weiß nicht</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
<style type="text/css"> .custom-array table.subquestion-list col {width: auto !important;} .custom-array table.subquestion-list thead .column-0 { width: 25%; } .custom-array table.subquestion-list thead .column-1 { width: 20%; } .custom-array table.subquestion-list thead .column-2 { width: 55%; } </style>