Welcome to the LimeSurvey Community Forum

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

Matrixfrage mit Kommentarfeld bei nur einer Unterfrage

  • kidim_vb
  • kidim_vb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 weeks ago - 3 years 3 weeks ago #212770 by kidim_vb
Dear Community

I am using LimeSurvey version 3.24.0 201013 server based.

Question 1
I am trying to add a comment field to item no. 5 of a matrix question, which contains 6 items. For this I read the thread [url] forums.limesurvey.org/forum/german-forum...rfeldern-kombinieren [/url] and tried to reduce the comment fields to only one specific sub-question - unfortunately without success. I do get it to have a comment field on each of the sub-questions, but not on just one sub-question.I still have printscreens uploaded. The way I want it to be (SHOULD) and the way it is now (IS).

Question 2
Furthermore, my survey is set to poll question by question, not question group by question group. Is my goal described above even possible with the setting "question by question" or does it really only work if the questions are asked per question group at once?

Thanks a lot for your help!
Last edit: 3 years 3 weeks ago by kidim_vb. Reason: Translated from German to English
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 weeks ago #212771 by tpartner
Please use English in this section of the forum.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 weeks ago #212780 by Joffm
Hi,
with my nearly not existing knowledge of javascript I did it quick and dirty.
I am sure ther will be an improvement.

In your javascript there is
Code:
$('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));
    });

This inserts the text field foreach row.

First I reduced the multiple text question to one item.
I forced the insertion into  the fifth row "eq(4)"
Code:
        $('li.answer-item', qMultiText).each(function(i) {
            // Move the text inputs into the array
            $('input[type="text"]', this).appendTo($('tr.answers-list:eq(4) .text-item', qArray));
        });

 


And your second question.

Furthermore, my survey is set to poll question by question, not question group by question group

Therefore we recommend to design the survey with one question per group.
Then you display "group by group" (the same look& feel as "question by question"), but you are able to insert such workarounds where you have to merge several questions into one.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 weeks ago #212781 by tpartner
If there is only one text input (or better you use a short-text type), you don't need the loop.

Code:
$('input[type="text"]:eq(0)', qMultiText).appendTo($('tr.answers-list:eq(4) .text-item', qArray));

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • kidim_vb
  • kidim_vb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 weeks ago #212783 by kidim_vb
Thank you very much, it works! Unfortunately our survey would work better with "question by question" because of different age-filters. Do you know about the workarounds where I can merge several questions into one?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 weeks ago #212787 by tpartner
This workaround will not work in question-by-question as JavaScript cannot access elements unless they are on the same page.

There is no difference between question-by-question and group-by-group if you place a single question in each group. Use single questions for all groups except this one.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • kidim_vb
  • kidim_vb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 weeks ago #212788 by kidim_vb
Well then I have no other option to choose group-by-group. Thank you for your quick answers!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 weeks ago #212801 by Joffm
If you change the question type to array(text) with dop-downs you may have it in one question.
 

array(text) with 
y-scale coded
Y001: Subquestion 1
Y002: Subquestion 2
...
x-scale coded
X001: Ja/Nein
X002: Kommentar

Then put these javascript and css snippets into the question text.

1. javascript to insert the dropdowns
Code:
<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>\
          <option value="4">Sag ich 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>

2. The javascript to hide the not necessary text fields
Code:
<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
     $('input[ name="{SGQ}Y001_X002"]').hide();
     $('input[ name="{SGQ}Y002_X002"]').hide();
     $('input[ name="{SGQ}Y003_X002"]').hide();
     $('input[ name="{SGQ}Y004_X002"]').hide();
     $('input[ name="{SGQ}Y006_X002"]').hide();
});
</script>

3. Some css to define the width of the columns
(in the first javascript we already added the class "custom-array")
Code:
<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>

Adapt to your needs.

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • kidim_vb
  • kidim_vb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 weeks ago #212802 by kidim_vb
Thanks a lot for the alternative solution and for all your efforts. It is great to have such LS experts!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose