Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Array question

  • peterpaul
  • peterpaul's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago #225727 by peterpaul
Array question was created by peterpaul
Please help us help you and fill where relevant: 
Your LimeSurvey version: 3.17.0+190402
Own server or LimeSurvey hosting: Open Universiteit Nederland
Survey theme/template: Advanced Template
==================
Is it possible to insert a comment box with an array question?
For my research the participants have to answer some array questions, but I want them to have the possibility to add additional text. Therefore, I wonder if this is possible, and if so: how.
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #225735 by Joffm
Replied by Joffm on topic Array question
Hi,
if you are able to reaqd Germen I recommend my "Tutorial 1" about arrays in the German part, Chapter 4.1.
[url] forums.limesurvey.org/forum/german-forum...nd-13-01-2022#223587 [/url]
Download the pdf.

Otherwise:
Create a question of type "multiple short text" after your array with as many subquestions as the array.
Enter this javascript code in the source code of the question.
Code:
<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.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>

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • peterpaul
  • peterpaul's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago #225801 by peterpaul
Replied by peterpaul on topic Array question
Thank you Joffm for your extensive and useful answer! I can use this.

Kind regards,

Peter-Paul.
 

Please Log in to join the conversation.

More
2 years 2 months ago #225838 by mt9999
Replied by mt9999 on topic Array question
Hi Joffm,

I'm wondering if you could help modify this code for me? I'm looking to do the same but with comment box (for numerical input only) for the second column instead of the last. I will be having an array table of 3 rows and 4 columns. In addition, is there a way to have a check box not appear in one of these cells?

I am using Version 5.2.13 and hosted on LimeSurvey.

Thank you kindly!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago - 2 years 2 months ago #225840 by tpartner
Replied by tpartner on topic Array question
Your request is confusing, particularly "is there a way to have a check box not appear in one of these cells?".

Can you provide a mockup?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 years 2 months ago by tpartner.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #225843 by Joffm
Replied by Joffm on topic Array question
Maybe this helps.
[url] forums.limesurvey.org/forum/can-i-do-thi...rrays?start=0#172220 [/url]
Neglect the upload part.

Second:
To remove checkboxes try this
Code:
<script type="text/javascript" charset="utf-8">$(document).ready(function() {// Remove in row 1
$('#question{QID} tr[id^="javatbd"]:eq(0) .checkbox-item:eq(0) *').remove();
$('#question{QID} tr[id^="javatbd"]:eq(0) .checkbox-item:eq(1) *').remove();
 
// Remove in row 6
$('#question{QID} tr[id^="javatbd"]:eq(5) .checkbox-item:eq(3) *').remove();
</script>

But, as @tpartner: your request is really confusing.
Either show an image or provide a lss, or best, both

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
2 years 2 months ago #225920 by mt9999
Replied by mt9999 on topic Array question
Hi everyone, sorry to have made it confusing.
I'm attaching both lss and an image for some additional help. 

Thank you again.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #225927 by Joffm
Replied by Joffm on topic Array question
Hi, you may use this
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete', function() {
    // Identify the questions
    var q1ID = {
      QID
    };
    var thisQuestion = $('#question' + q1ID);
    var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
    var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
    //Hide the multiple-short-text
    nextQuestion.hide();
    // Move the text inputs
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
      $('td.answer-item:first input[type="radio"]', this).css({
        'position': 'absolute',
        'left': '-9999em'
      });
      $('td.answer-item:first', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X' + q2ID + thisCode + '"]', nextQuestion));
    });
    // Listeners on the text inputs
    $('input[type="text"]', thisQuestion).on('keyup change', function(e) {
      var thisRadio = $(this).closest('td').find('input[type="radio"]');
      var thisRadioVal = thisRadio.val();
      if ($.trim($(this).val()) != '') {
        $(thisRadio).trigger('click');
      } else {
        $(thisRadio).prop('checked', false);
        thisRadioVal = '';
      }
      // Reset Expression manager
      checkconditions(thisRadioVal, $(thisRadio).attr('name'), 'radio', 'click');
    });
    // Listeners on the radios
    $('input[type="radio"]', thisQuestion).on('click', function(e) {
      if (!$(this).closest('td').hasClass('inserted-text-item')) {
        $(this).closest('tr').find('input[type="text"]').val('');
      }
    });
  });
</script>

Don't show the first subquestion, the third answer option
Code:
<style type="text/css">
  tr[id^="javatbd{SGQ}SQ001"] .answer_cell_AO03 {
     display:none;
  }
</style>

Unfortunately I was not able to include the <style></style> in the javascript

 

Further styling is up to you.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
2 years 2 months ago #225930 by mt9999
Replied by mt9999 on topic Array question
Sorry to be a pain, Joffm. For some reason, my question isn't changing after entering the code you shared. I've created a multiple short text question after this array question with two subquestions that I've left blank. Am I missing something?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #225935 by Joffm
Replied by Joffm on topic Array question
Here my example.
 

File Attachment:

File Name: limesurvey...7623.lss
File Size:43 KB

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: mt9999

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose