Welcome to the LimeSurvey Community Forum

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

Matrix where some subquestions got comments

  • McTell
  • McTell's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 years 2 months ago #163050 by McTell
Hey,

I’ve got a Matrix of different questions in LimeSurvey. Yet, some of them require the participant to specify an answer. I would like to have a "comment" text filed behind that specific questions.

The most helpful approach was this one (also check the attachment):
www.limesurvey.org/forum/can-i-do-this-w...w--my-solution#89695

As you also see the attachment I want to control on what subquestions this comment field is shown. Is this somehow possible?


Thanks for any help,
McTell
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #163074 by tpartner
Replied by tpartner on topic Matrix where some subquestions got comments
What LS version are you using?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • McTell
  • McTell's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 years 2 months ago #163103 by McTell
Replied by McTell on topic Matrix where some subquestions got comments
Version 2.00+ Build 130514

but maybe at some point our institutes uses a different hoster, that uses Version 2.72.5+171121 and upgrades much more eagerly...

I’d prefer responding for 2.00, though.

many thanks,
mctell
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
6 years 2 months ago #163113 by LouisGac
Replied by LouisGac on topic Matrix where some subquestions got comments
2.0.x has known critical vulnerabilities.
Your institute should update as soon as possible.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #163127 by tpartner
Replied by tpartner on topic Matrix where some subquestions got comments
I agree that you should update.

I cannot test on 2.0, but this should work...

1) Create the array question.

2) Add a multiple-short-text question after the array with sub-question codes identical to those of the array where you want the text inputs inserted.

3) Add the following script to the source of the array question. The script will hide the multiple-short-text question and add its question text and text inputs to the corresponding array rows.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
 
    // Identify the questions
    var q1ID = '{QID}';
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).next('div[id^="question"]');
    var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
    // Hide the multi-text question
    $(nextQuestion).hide();
 
    // Add extra cells to the array rows
    $('.subquestions-list thead tr', thisQuestion).append('<th />');
    $('.subquestions-list tbody tr', thisQuestion).append('<td />');
 
    // Move the multi-text question text to the last column header cell of the array
    $('.subquestions-list thead tr th:last', thisQuestion).text($('.questiontext', nextQuestion).text());
 
    // Move the text inputs
    $('input.text', nextQuestion).each(function(i){
      var thisCode = $(this).attr('id').split('X'+q2ID)[1];
      $('.subquestions-list tbody tr[id$="X'+q1ID+thisCode+'"] td:last', thisQuestion).append(this);
    });
 
    // Some cleanup styles
    $('col', thisQuestion).css({
      'width': 'auto'
    });
    $('.subquestions-list tbody th, .subquestions-list tbody td', thisQuestion).css({
      'padding': '4px 10px'
    });
  });
</script>


This script will work for 2.7x and 3.x:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
 
    // Identify the questions
    var q1ID = '{QID}';
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).next('div[id^="question"]');
    var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
    // A class for the array question
    $(thisQuestion).addClass('with-inserted-texts');
 
    // Hide the multi-text question
    $(nextQuestion).hide();
 
    // Add extra cells to the array rows
    $('.subquestion-list thead tr', thisQuestion).append('<th class="text-center" />');
    $('.subquestion-list tbody tr', thisQuestion).append('<td />');
 
    // Move the multi-text question text to the last column header cell of the array
    $('.subquestion-list thead tr th:last', thisQuestion).text($('.questiontext', nextQuestion).text());
 
    // Move the text inputs
    $('input[type="text"]', nextQuestion).each(function(i){
      var thisCode = $(this).attr('id').split('X'+q2ID)[1];
      $('.subquestion-list tbody tr[id$="X'+q1ID+thisCode+'"] td:last', thisQuestion).append(this);
    });
 
    // Insert some styles 
    var newStyles = '.with-inserted-texts col { \
              width: auto !important; \
            } \
            .with-inserted-texts .subquestion-list tbody th,\
            .with-inserted-texts .subquestion-list tbody td { \
              padding: 4px 10px; \
            } \
            .with-inserted-texts .subquestion-list tbody th,\
            .with-inserted-texts .subquestion-list tbody td { \
              height: 50px; \
              vertical-align: middle; \
            } \
            .with-inserted-texts .radio label::before,\
            .with-inserted-texts .radio label::after { \
            }';  
    $('head').append('<style type="text/css">'+newStyles+'</style>');
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • McTell
  • McTell's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 years 2 months ago #163160 by McTell
Replied by McTell on topic Matrix where some subquestions got comments
Getting a JavaScript Error:

Code:
Uncaught TypeError: Cannot read property 'replace' of undefined

Not sure how to resolve this... I attached the lss with you instructions.

Thanks for any advice.

Best,
McTell
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #163167 by tpartner
Replied by tpartner on topic Matrix where some subquestions got comments
Can you activate a test survey and give a link?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • McTell
  • McTell's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 years 2 months ago #163191 by McTell
Replied by McTell on topic Matrix where some subquestions got comments
The error is gone, hiding the text field works, yet I don’t see the text field at all, not even next to it:

survey.cbs.mpg.de/index.php/714867/lang-en
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #163195 by tpartner
Replied by tpartner on topic Matrix where some subquestions got comments
You have not followed my instructions! Your second question is a short-text, not a multiple-short-text.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • McTell
  • McTell's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 years 2 months ago #163199 by McTell
Replied by McTell on topic Matrix where some subquestions got comments
Damn, it’s working now. Thanks!!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose