Welcome to the LimeSurvey Community Forum

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

Multiple text entry on array quesiton

  • tixeon
  • tixeon's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #204056 by tixeon
Hi, I want to create an array where people can enter free text and then rate the free text they have entered. I have tried to use the multiple question types in array workaround but it doesn't work in my version (3.23.0, professional hosted)



The rating scale can be either drop-down or radio, I jsut need them to be able to type in their own options for each row.

I have attached my attempt. I suspect the workaround javascript is for an earlier version and I am not familiar with the correct terminology for the latest version.


File Attachment:

File Name: limesurvey...5487.lss
File Size:34 KB
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months ago #204065 by Joffm
Replied by Joffm on topic Multiple text entry on array quesiton
Hi,
this is really a very very old script.

Why don't you use an array(text) with dropdowns?
Many times shown here in the forum.


And with subquestion relevance you display row by row
Row 2: !is_empty(self.sq_Y001_X001) and !is_empty(self.sq_Y001_X002)
Row 3: !is_empty(self.sq_Y002_X001) and !is_empty(self.sq_Y002_X002)
...
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Select...</option>\
                          <option value="1">Not important at all</option>\
                          <option value="2">2</option>\
                          <option value="3">3</option>\
                          <option value="4">4</option>\
                          <option value="5">Very important</option>\
                          <option value="6">Don´t know</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>

Example without columns of different widths.

File Attachment:

File Name: limesurvey...6693.lss
File Size:23 KB


There are also some solutions to vary the column widths.
1. javascript
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    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);
      });
    });
    });
</script>

2. css
Code:
<style type="text/css">.custom-array table.subquestion-list col {
    width: auto !important;
  }
 
  .custom-array table.subquestion-list thead .column-0 {  width: 5%; } 
  .custom-array table.subquestion-list thead .column-1 {  width: 80%; }
  .custom-array table.subquestion-list thead .column-2 {  width: 15%; }
</style>

And a code "Don't know", if I am inserting my own items?

Or do you plan a different array?
An array with precodes AND additional others to rate?
Like this?


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 8 months ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204073 by Joffm
Replied by Joffm on topic Multiple text entry on array quesiton
Here a small variation.
You may use it with precoded items or without



File Attachment:

File Name: limesurvey...5451.lss
File Size:26 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204102 by holch
Replied by holch on topic Multiple text entry on array quesiton
There is also the option to just use two questions:

Ask the items in a multiple text question, then pipe the answers into your array for respondents to evaluate.

Yes, it is one more question, but it is a clean approach, out of the box.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204104 by Joffm
Replied by Joffm on topic Multiple text entry on array quesiton
I assumed that tixeon knows this.
He is a long-time user of Limesurvey (at least 6 years)

So I wanted to contribute some other options.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204139 by holch
Replied by holch on topic Multiple text entry on array quesiton
Yeah, but sometimes people just don't see the easy way out, because they are focused on their paper form, etc.

So I just wanted to add the simple solution, just in case. ;-)

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More
3 years 8 months ago #204183 by karld
Replied by karld on topic Multiple text entry on array quesiton
Hello,

This is exactly what I am trying to achieve, but the text from the answer to the first question doesn't appear in the second question:



What am I missing?

Thanks in advance.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months ago #204184 by Joffm
Replied by Joffm on topic Multiple text entry on array quesiton
Hi,
obviously you did not pipe the answers of the first question into the subquestions of the second.

Please, always provide lss exports, neither lsq nor lsg.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 8 months ago by Joffm.
The topic has been locked.
More
3 years 8 months ago #204188 by karld
Replied by karld on topic Multiple text entry on array quesiton
> obviously you did not pipe the answers of the first question
> into the subquestions of the second.

Indeed. I thought putting the question code in Logic > Array filter would do it, but it seems not. How to proceed?

Here is the .lss.

Thanks for your help.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204190 by Joffm
Replied by Joffm on topic Multiple text entry on array quesiton
Hi,
  1. Remove the array filter. This is something different.
  2. Change the first question to "multiple short text" as @holch wrote.
  3. At the moment it is an array(text) without columns.
  4. Pipe the answers of es1 into es2.
    {es1_SQ001}
    {es1_SQ002}
    ...
  5. Set the subquestion relevance of the es2 subquestions to
    !is_empty(es1_SQ001)
    !is_empty(es1_SQ002)
    ...

Joffm

Therefore
Read the manual about question types
manual.limesurvey.org/Question_types
Study the sample survey
manual.limesurvey.org/ExpressionScript_s...loring_and_Equations
Read the manual about "Access to variables
manual.limesurvey.org/ExpressionScript_-...#Access_to_variables

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: karld
The topic has been locked.
More
3 years 8 months ago #204193 by karld
Replied by karld on topic Multiple text entry on array quesiton
Works like a charm, thanks a lot.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose