Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ $("#answer{SGQ}SQ001_SQ001").mask("999.999.999-99",{ placeholder:" " }); // Listener on the text input $('#answer{SGQ}SQ002_SQ002').on('keyup', function(e) { $(this).val($(this).val().toUpperCase()); checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type')); }); $("#answer{SGQ}SQ001_SQ002").val(" "); $("#answer{SGQ}SQ001_SQ002").hide(); // Identify the questions var qArrayID = '{QID}'; var qArray = $('#question'+qArrayID); var arrayLength = $('tr[id^="javatbd"]', qArray).length; var qUploads = qArray.nextAll('.upload-files:lt('+arrayLength+')'); // Add some classes qArray.addClass('array-with-uploads-question'); $(qUploads).addClass('d-none'); // Insert the "Upload" buttons $('tr[id^="javatbd"] .answer-item:last-child', qArray).each(function(i) { $('*', this).remove(); $(this).append('<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#upload-'+qArrayID+'-'+(i+1)+'" data-bs-backdrop="static" data-bs-keyboard="false">Anexar comprovante</button>'); }); // Loop through the upload questions $(qUploads).each(function(i) { // Create a modal $('body').append('<div class="modal fade upload-modal" id="upload-'+qArrayID+'-'+(i+1)+'" tabindex="-1" aria-labelledby="uploadModalLabel'+qArrayID+'-'+(i+1)+'" aria-hidden="true">\ <div class="modal-dialog">\ <div class="modal-content">\ <div class="modal-header">\ <h5 class="modal-title" id="uploadModalLabel'+qArrayID+'-'+(i+1)+'">'+$('.ls-label-question', this).html()+'</h5>\ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fechar"></button>\ </div>\ <div class="modal-body">\ </div>\ <div class="modal-footer">\ <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>\ </div>\ </div>\ </div>\ </div>'); // Move this question into the modal $('#upload-'+qArrayID+'-'+(i+1)+' .modal-body').append($(this)); $(this).removeClass('d-none'); }); // Interrupt the Previous/Next/Submit function (to put upload questions back in the form) $('#limesurvey').on('submit', function(e) { $('.upload-modal .upload-files').appendTo($('.group-container:eq(0)')).addClass('d-none'); }); }); </script> <style data-author="Tony Partner" type="text/css"> .upload-modal .file-upload-modal.in { height: max-content; } </style>
<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(); var tableWidth = $('table.questions-list:eq(0)', qArray).width(); var answerWidth = $('col.ls-col-odd:eq(0)', qArray).width(); var answerWidthPercent = (answerWidth/tableWidth)*100; var answersLength = $('col.ls-col-odd, col.ls-col-even', qArray).length; var answerWidthPercent2 = (answerWidthPercent*answersLength)/(answersLength+1) $('table.questions-list col', qArray).removeAttr('width'); $('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.subquestion-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.subquestion-list:eq('+i+') .text-item', qArray)); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i); }); }); // Insert checkboxes $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3', thisQuestion).addClass('custom-checkbox-item'); $('.custom-checkbox-item', thisQuestion).each(function(i) { var thisID = $('input:text:eq(0)', this).attr('id'); $('label', this).before('<input class="" id="'+thisID+'" value="Y" type="checkbox" name="'+thisID.replace(/answer/, '')+'" />'); if($('input:text:eq(0)', this).val() == 'Y') { $('input:checkbox:eq(0)', this).prop('checked', true); } $(this).removeClass('text-item').addClass('checkbox-item'); $('input:text:eq(0)', this).remove(); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to make the last option in a single-column multiple choice exclusive function excludeOpt(qID) { var thisQuestion = $('#question' + qID); // Add classes to the checkbox items $('input[type="checkbox"]', thisQuestion).each(function(i) { $(this).closest('li').addClass('normal-item'); }); // Mark the last checkbox as exclusive $('li.normal-item:last', thisQuestion).removeClass('normal-item').addClass('exclusive-item'); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function(event) { handleExclusive($(this).closest('li')); }); function handleExclusive(thisItem) { // Uncheck the appropriate boxes if ($(thisItem).hasClass('normal-item')) { $('.exclusive-item input[type="checkbox"]', thisQuestion).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisQuestion).prop('checked', false); } // Check conditions (relevance) $('li.checkbox-item', thisQuestion).each(function(i) { var thisValue = ''; if ($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
No, it is not.However, there is still a bit mistake.
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">very low</option>\ <option value="2">low</option>\ <option value="3">medium</option>\ <option value="4">good</option>\ <option value="5">very good</option>\ </select>'); $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">very low</option>\ <option value="2">low</option>\ <option value="3">medium</option>\ <option value="4">good</option>\ <option value="5">very good</option>\ </select>'); $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">very low</option>\ <option value="2">low</option>\ <option value="3">medium</option>\ <option value="4">good</option>\ <option value="5">very good</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>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $("#answer{SGQ}Y001_X001").prop('disabled', true); $("#answer{SGQ}Y002_X001").prop('disabled', true); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the sub-heading text strings var subHeading1 = '<span style="color:maroon;font-size:12pt;font-weight:bold">Others (optional)</span>'; var columnsLength = $('tr.subquestion-list:eq(0) > *', thisQuestion).length; // Insert the new rows $('tr.subquestion-list:eq(2)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading1+'</th></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>
See this post - forums.limesurvey.org/forum/can-i-do-thi...th-checkboxes#227597...but was unsuccessfully able to make one of my subquestions exclusive per column.
$('tr[id^="javatbd"]:first td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');
$('tr[id^="javatbd"]:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the sub-heading text strings var subHeading = '<th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th>'; var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length; // Insert the new rows $('tr.answers-list:eq(1)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); $('tr.answers-list:eq(2)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); $('tr.answers-list:eq(3)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); // For all subquestions - or however you want // Fix up the row classes var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>
<style type="text/css"> .sub-header-row { color: maroon; font-weight:bold; text-align: center; } </style>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to make the last option in each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exlusive-item input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qArrayID = '{QID}'; var qArray = $('#question'+qArrayID); var arrayLength = $('tr[id^="javatbd"]', qArray).length; var qComments = qArray.nextAll('.text-long:lt('+arrayLength+')'); // Add some classes qArray.addClass('array-with-comments-question'); $(qComments).addClass('hidden'); // Insert the "Upload" buttons $('tr[id^="javatbd"] .answer-item:last-child', qArray).each(function(i) { $('*', this).remove(); $(this).append('<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#comment-'+qArrayID+'-'+(i+1)+'" data-backdrop="static" data-keyboard="false">Comment</button>'); }); // Loop through the upload questions $(qComments).each(function(i) { // Create a modal $('body').append('<div class="modal comment-modal" id="comment-'+qArrayID+'-'+(i+1)+'" tabindex="-1" role="dialog">\ <div class="modal-dialog" role="document">\ <div class="modal-content">\ <div class="modal-header">\ <h5 class="modal-title">'+$('.ls-label-question', this).html()+'Please, enter your comment</h5>\ </div>\ <div class="modal-body">\ </div>\ <div class="modal-footer">\ <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>\ </div>\ </div>\ </div>\ </div>'); // Move this question into the modal $('#comment-'+qArrayID+'-'+(i+1)+' .modal-body').append($(this)); $(this).removeClass('hidden'); }); // Interrupt the Next/Submit function (to put upload questions back in the form) $('#ls-button-submit').on('click', function(e) { $('.comment-modal .text-long').appendTo($('.group-container:eq(0)')).addClass('hidden'); }); }); </script> <style data-author="Tony Partner" type="text/css"> .comment-modal .comment-modal.in { height: max-content; } </style>
// Label 1 var label1 = $('<label class="col-12 col-md-3 slider-right">Label 1</label>'); $('#javatbd{SID}X{GID}X{QID}1 .ls-slider-item-row').append(label1); $('#label-{SID}X{GID}X{QID}1').removeClass('col-md-4').addClass('col-md-3 mb-0'); $('#javatbd{SID}X{GID}X{QID}1 .px-md-5').removeClass('col-md-8').addClass('col-md-6'); // Label 2 var label2 = $('<label class="col-12 col-md-3 slider-right">Label 2</label>'); $('#javatbd{SID}X{GID}X{QID}2 .ls-slider-item-row').append(label2); $('#label-{SID}X{GID}X{QID}2').removeClass('col-md-4').addClass('col-md-3 mb-0'); $('#javatbd{SID}X{GID}X{QID}2 .px-md-5').removeClass('col-md-8').addClass('col-md-6'); // Label 3 var label3 = $('<label class="col-12 col-md-3 slider-right">Label 3</label>'); $('#javatbd{SID}X{GID}X{QID}3 .ls-slider-item-row').append(label3); $('#label-{SID}X{GID}X{QID}3').removeClass('col-md-4').addClass('col-md-3 mb-0'); $('#javatbd{SID}X{GID}X{QID}3 .px-md-5').removeClass('col-md-8').addClass('col-md-6');
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to make the last option in each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item1') $('.normal-item:eq(-1)', this).removeClass('normal-item').addClass('exlusive-item2') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); } else if ($(thisCell).hasClass('exlusive-item1')) { $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } else if ($(thisCell).hasClass('exlusive-item2')) { $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>