Welcome to the LimeSurvey Community Forum

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

Matrixfrage mit Kommentarfeldern kombinieren

  • HeNaTi
  • HeNaTi's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #204726 by HeNaTi
Hallo,

ich arbeite mit der Version 3.22.25+200706, mit dem Browser Firefox und dem Betriebssystem Windows 10.

Ich bin blutiger Anfänger und möchte gerne 2 Fragen miteinander kombinieren. Ich habe eine Matrixfrage erstellt. Diese ist als Pflichtfrage markiert. Die Teilfragen sollen mit "ja/nein/kann ich nicht beantworten" beantwortet werden. Nun soll man aber unabhängig von der Antwort auch einen Kommentar hinterlassen können. Bisher habe ich eine weitere Frage (in der gleichen Fragengruppe, mit Anzeigeformat Gruppe für Gruppe) erstellt mit mehrfachen kurzen Texten. Das Ergebnis ist leider sehr unschön, da man ca. 25 Teilfragen beantworten muss und somit die Kommentarfelder zu sehr aus dem Fokus geraten.

Nun meine Frage. Kann man irgendwie eine Matrixfrage erstellen, wo gleich hinter oder direkt unter jeder Teilfrage ein Kommentarfeld erscheint?

Danke.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago - 3 years 7 months ago #204729 by Joffm
Hallo, HeNaTi!

Ja, kann man.


Dabei wird einfach die multiple Textfrage per javascript in die Matrix "hineingemauschelt".
Beispiel später.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 7 months ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204731 by Joffm
So, hier ist ein Beispiel.
Füge das folgende script in den Fragetext der Matrix ein (Quellcode-Modus)
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();
 
      $('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>

Die Spaltenbreite der Bemerkungsspalte kannst Du im script ändern.
$('table.questions-list thead tr th.answer-text.inserted-column-label', qArray).css('width','30%');

Dann kommt so etwas heraus.


Sample

File Attachment:

File Name: limesurvey...3857.lss
File Size:25 KB


Viel Erfolg
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: HeNaTi
The topic has been locked.
  • HeNaTi
  • HeNaTi's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #207899 by HeNaTi
Hallo,

ich brauche zu diesem Thema leider nochmal Hilfe. Kann man überhaupt in einen alten Eintrage nochmal nachfragen?

Ich habe das Javascript so eingebaut und es läuft prima. Jetzt wird allerdings eine Randomisierung der Teilfragen gewünscht. Das Problem ist dabei, dass die Kommentarfelder nicht wirklich mit den Teilfragen verknüpft sind. Das heißt, wenn ich die Teilfragen randomisiere, dann wandern die Kommentarfelder nicht mit.
Wie kann ich die Kommentarfelder den entsprechenden Teilfragen fest zuordnen wenn ich die Teilfragen randomisieren möchte?

Gruß
HeNaTi
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207917 by Joffm
Hallo,
genau so sieht es aus.
D.h. Du musst Dir etwas anderes überlegen.

1. Lege die Frage mehrmals an mit verschiedenen Reihenfolgen der Items. Grundsätzlich sollte einmal vorwärts, einmal rückwärts, einmal von der Mitte aus alle geraden Items dann die ungeraden, und noch einmal umgekehrt ausreichen.

2. Da es im Grunde jeweils "Einfachnennung mit Kommentar"-Fragen sind, lege sie einzeln an und randomisiere über "Randomisierungsgruppenname".

3. Du kannst auch einen ganz anderen Fragentyp nehmen, eine Matrix(Texte) mit der dropdown-Lösung.


Da es sich um eine Matrix(Texte) handelt, werden die Ergebnisse der J/N-Frage auch als Text gespeichert.
Entweder Du kodierst später um, oder jemand macht sich die Mühe, das Forum zu durchsuchen; es gibt irgendwo eine Lösung, nicht den Text, sondern den Wert zu speichern (dann steht doert statt "Ja" eben eine "1" - zwar immer nocht Text, aber anders).
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>\
</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>
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: 15%; }
  .custom-array table.subquestion-list thead .column-2 {  width: 60%; }
</style>

Das css ist nur da, um die Breite der Spalten zu definieren.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207925 by Joffm
Und mit dieser kleinen Änderung werden die Codes gespeichert, nicht die Texte der 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>\
</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>
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>

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
2 years 9 months ago #217712 by SBFI_survey
Replied by SBFI_survey on topic Matrixfrage mit Kommentarfeldern kombinieren
Hallo Joffm
Die Integration des Javascipts gibt bei mir (Version 3.27.6+210629) folgende Seite aus: Hätte ich da die Parameter noch anpassen müssen? Und wenn ja, welche?
(Ich bin in Sachen Javascript ziemlich unbedarft...)
Danke für deine Hilfe
Philip
[img
The topic has been locked.
Moderators: Joffm

Lime-years ahead

Online-surveys for every purse and purpose