Welcome to the LimeSurvey Community Forum

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

Sub-Categories for Array (Numbers)

  • Sokrates_Mikesch
  • Sokrates_Mikesch's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 week ago #264839 by Sokrates_Mikesch
Sub-Categories for Array (Numbers) was created by Sokrates_Mikesch
LimeSurvey version: Version 3.14.8+180829
Own server or LimeSurvey hosting: unknown (University version)

==================
Hi everyone

I do have the following question: I want to use Limesurvey for a Social Network Analysis (SNA). My idea is to use the question type "Array (Numbers)" and have a checkbox layout that allows for multiple checks per row. In the row, I want to have the different organizations that the survey participant could have relationships with (roster list). In the column, I want to describe the relationship (e.g. "trade relationship", "collaboration relationship", etc.). In this way, I hope that participants can easily go through the list the check the types of relationships that they have with the organisations in the roster list. Since this roster is quite long, I would like to form categories of organisations (e.g. Restaurants, Processing Companies, Retail, etc.). How can I code this in Limesurvey? An example (just the question type and the roster, without the categories) is attached.

In addition to the roster, I then will have an additional question where participants can name organizations that are not on the roster list but still relevant for the relationships described.

I already found a thread that has a similiar problem, however, I could not solve mine with it: [url] forums.limesurvey.org/forum/design-issue...uestions-by-category [/url]

Does this design make sense when it comes to evaluating the data?
Thank you a lot in advance already!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago - 6 months 1 week ago #264855 by tpartner
Replied by tpartner on topic Sub-Categories for Array (Numbers)

Since this roster is quite long, I would like to form categories of organisations (e.g. Restaurants, Processing Companies, Retail, etc.). How can I code this in Limesurvey?

The simplest way would be to use separate questions for the categories and maybe visually merge them with CSS.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 months 1 week ago by tpartner.
The following user(s) said Thank You: Sokrates_Mikesch

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago - 6 months 1 week ago #264862 by Joffm
Replied by Joffm on topic Sub-Categories for Array (Numbers)
Hi,
I could offer this
 

Seeing the base language of the shown survey you seem to be able to read German.
Everything you find in my "Tutorial 1: Matrizen" in the German part on page 8, 9 ,10,... (have a look)
1. Additional rows for "Others", Chapter 3.1.
2. Additional Headers, Chapter 5.1.
3. Exclusiveness of last two checkboxes, Chapter 8.1.3.
4. Left alignment of subquestion text, Chapter 16

I can't send an example.
I do not have your ancient version (nearly 6 years old, without security patches, without bug fixes)
But the examples of the tutorial work in LS 3.x.

And make sure that you can use javascript. Often forbidden in university installations.
If not, @tpartner already mentioned the merging of question with some css classes.

Joffm



 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 months 1 week ago by Joffm.
The following user(s) said Thank You: Sokrates_Mikesch

Please Log in to join the conversation.

  • Sokrates_Mikesch
  • Sokrates_Mikesch's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 week ago - 6 months 1 week ago #264879 by Sokrates_Mikesch
Replied by Sokrates_Mikesch on topic Sub-Categories for Array (Numbers)
Thank you a lot! This works already pretty good! I now use the following code:
Code:
/* Teilfragentexte linksbündig */
.ls-answers tbody .answertext {
text-align: left;
}<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
    // Identify this question
    var thisQuestion = $('#questionID');
 
    // Define the sub-heading text strings
    var subHeading1 = '<span style="color:blue;font-size:12pt;font-weight:bold">Kategorie A</span>';
    var subHeading2 = '<span style="color:blue;font-size:12pt;font-weight:bold">Kategorie B</span>';
    var subHeading3 = '<span style="color:blue;font-size:12pt;font-weight:bold">Weitere</span>';
 
    // Get the number of columns in the first row
    var columnsLength = $('tr.subquestion-list:eq(0) > *', thisQuestion).length;
 
    // Insert the new rows with sub-headings
    $('tr.subquestion-list:eq(0)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading1+'</th></tr>');
    $('tr.subquestion-list:eq(3)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading2+'</th></tr>');
    $('tr.subquestion-list:eq(5)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading3+'</th></tr>');
 
    // Fix up the row classes to maintain alternating row colors
    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');
            }
        }
    });
 
    // Call the function to make the last two options in each array row exclusive
    excludeOpt('questionID');
 
    // Hide short-text questions and move them into the array
    hideAndMoveShortText();
});
 
// Eine Funktion, um die letzten zwei Optionen in jeder Array-Zeile exklusiv zu machen
function excludeOpt(questionID) {
    var thisQuestion = $('#questionID');
 
    // Fügen Sie den Checkbox-Zellen einige Klassen hinzu
    $('td.checkbox-item', thisQuestion).addClass('normal-item');
 
    // Schleife durch jede Zeile und markiere die letzten beiden Elemente als exklusiv
    $('tr.subquestion-list', thisQuestion).each(function(i) {
        var $cells = $(this).find('.checkbox-item');
        $cells.eq(-1).removeClass('normal-item').addClass('exclusive-item');
        $cells.eq(-2).removeClass('normal-item').addClass('exclusive-item');
    });
 
    // Ein Listener auf den Kontrollkästchen
    $('input[type="checkbox"]', thisQuestion).on('change', function (event) {
        handleExclusive($(this).closest('td'));
    });
}
 
// Funktion zum Ausblenden und Verschieben von Kurztextfragen
function hideAndMoveShortText() {
    // Identify the questions
    var thisQuestion = $('#questionID');
    var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
    var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)');
    var nextQuestions = $(nextQuestion1).add(nextQuestion2);
    var nextLength = nextQuestions.length;
    var sqLength = $('tr.answers-list', thisQuestion).length;
 
    // Hide the short-text questions
    $(nextQuestions).hide();
 
    // Move the hidden text inputs into the array
    for (i = 0; i < nextLength; i++) {
        var workingIndex = (sqLength - 1) - (nextLength - i) + 1; // Erhöhen Sie den Index um 1
        var nextQ = nextQuestions[i];
        var answerText = $(nextQ).find('input[type="text"]').val();
        var inputElement = '<input type="text" value="' + answerText + '" disabled>';
        $('th.answertext:eq('+workingIndex+')', thisQuestion).append(inputElement).closest('tr').addClass('otherRow');
    }
 
    // Some styling...
    $('input[type="text"]', thisQuestion).css({
        'width': '100%'
    });
}
 
function handleExclusive(thisCell) {
    var thisRow = $(thisCell).closest('tr');
 
    // Aktivieren oder deaktivieren Sie die entsprechenden Kontrollkästchen in einer Zeile
    if ($(thisCell).hasClass('normal-item')) {
        $('.exclusive-item input[type="checkbox"]', thisRow).prop('checked', false);
    } else {
        $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false);
    }
 
    // Überprüfen Sie die Bedingungen (Relevanz)
    $('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>
<style type="text/css">/* Teilfragentexte linksbündig */
.ls-answers tbody .answertext {
text-align: left;
}
</style>[/i]

Now, is there a possibility to use the sub-category title line to also repeat the x-scale questions (trade relationship, collaboration relationship, ...)?
Last edit: 6 months 1 week ago by Sokrates_Mikesch.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago - 6 months 1 week ago #264881 by Joffm
Replied by Joffm on topic Sub-Categories for Array (Numbers)
Of course.

You see the line to insert the subheaders
There is one row with a colspan of the entire width.
<th colspan="'+columnsLength+'">

Use a colspan of; "1" (or no colspan at all) and display your texts,
like
Code:
   
        $('tr.subquestion-list:eq(5)', thisQuestion).before('<tr class="sub-header-row">\        
            <th>'+subHeading3+'</th>\
            <th style="font-weight:bold;text-align:center">Trade Relationship</th>\
            <th style="font-weight:bold;text-align:center">Collaboration Relationship</th>\
            <th style="font-weight:bold;text-align:center">No Relation</th>\
            <th style="font-weight:bold;text-align:center">No answer</th>\
        </tr>');    

 
Rough example.
Better to use a class to style these subheaders.


Alternative:
Create the entire cells in the variable
Code:
      var subHeading1 = '<th style="color:maroon;font-size:12pt;font-weight:bold">Category A-B</th>';
      var subHeading2 = '<th style="color:maroon;font-size:12pt;font-weight:bold">Category C-E</th>';
      var subHeading3 = '<th style="color:maroon;font-size:12pt;font-weight:bold">Category F-G</th>';
      
      var option1 = '<th style="font-weight:bold;text-align:center">Trade Relationship</th>';
      var option2 = '<th style="font-weight:bold;text-align:center">Collaboration Relationship</th>';
      var option3 = '<th style="font-weight:bold;text-align:center">No Relationship</th>';
      var option4 = '<th style="font-weight:bold;text-align:center">No answer</th>';
...
     
        // Insert the new rows
        $('tr.subquestion-list:eq(5)', thisQuestion).before('<tr class="sub-header-row">'+subHeading3+option1+option2+option3+option4+' </tr>');    



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 months 1 week ago by Joffm.
The following user(s) said Thank You: Sokrates_Mikesch

Please Log in to join the conversation.

  • Sokrates_Mikesch
  • Sokrates_Mikesch's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 3 days ago #265021 by Sokrates_Mikesch
Replied by Sokrates_Mikesch on topic Sub-Categories for Array (Numbers)
I works!! Thanks a lot!

Your guide is awesome! :)

Please Log in to join the conversation.

  • Sokrates_Mikesch
  • Sokrates_Mikesch's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 months 3 weeks ago - 5 months 3 weeks ago #265222 by Sokrates_Mikesch
Replied by Sokrates_Mikesch on topic Sub-Categories for Array (Numbers)
Hi again - i have a follow-up question:

Apparently, LimeSurvey automatically inserts Sub-Headers every 25 rows. Is there a way to disable this?

Otherwise, it looks quite weird if I have my category rows (with sub-headers) and additionally every 25 rows another sub-header (without category).

I tried with this, but without success:
Code:
function removeRepeatedHeadings() {
    var thisQuestion = $('#question128793');
    var repeatedHeadings = $('table.subquestions-list thead th.repeated-heading', thisQuestion);
    repeatedHeadings.closest('tr').remove();
}
Last edit: 5 months 3 weeks ago by Sokrates_Mikesch. Reason: more info

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 months 3 weeks ago #265224 by Joffm
Replied by Joffm on topic Sub-Categories for Array (Numbers)
1. Read the manual about question types (here "array")

2. Have a look at the settings of the question!
Nearly each option has a question mark that shows amd explains its meaning.

Joffm 

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

Please Log in to join the conversation.

  • Sokrates_Mikesch
  • Sokrates_Mikesch's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 months 2 weeks ago #265386 by Sokrates_Mikesch
Replied by Sokrates_Mikesch on topic Sub-Categories for Array (Numbers)
Hi
I am once again struggling with topic "additional rows for others in array" (as described in your tutorial im chapter 3.1). Now the good thing is: it worked when I had 1 array question per question group. Now my corrector wants to have separate arrays for each category. With more than 1 array in the same question group, I get weird previews (see photo). I used the following code. Can you help me again?
Code:
// Funktion zum Ausblenden und Verschieben von Kurztextfragenfunction hideAndMoveShortText() {    // Identify the questions    var thisQuestion = $('#question128793');    var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');    var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)');    var nextQuestions = $(nextQuestion1).add(nextQuestion2);    var nextLength = nextQuestions.length;    var sqLength = $('tr.answers-list', thisQuestion).length;     // Hide the short-text questions    $(nextQuestions).hide();     // Move the hidden text inputs into the array    for (i = 0; i < nextLength; i++) {        var workingIndex = (sqLength - 1) - (nextLength - i) + 1; // Erhöhen Sie den Index um 1        var nextQ = nextQuestions[i];        var answerText = $(nextQ).find('input[type="text"]').val();        var inputElement = '<input type="text" value="' + answerText + '">';        $('th.answertext:eq('+workingIndex+')', thisQuestion).append(inputElement).closest('tr').addClass('otherRow');    }     // Some styling...    $('input[type="text"]', thisQuestion).css({        'width': '100%'    });}

 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 months 2 weeks ago #265387 by Joffm
Replied by Joffm on topic Sub-Categories for Array (Numbers)

Can you help me again?


1. I neither understand, what you want to do nor your screenshot.
.At least send a lss export 
2. I am tired to discuss this in English without need. There is always a language gap.

Joffm
 

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

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose