Welcome to the LimeSurvey Community Forum

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

Customized table with token and questions

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228714 by CarlottaToletti
Customized table with token and questions was created by CarlottaToletti
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.3.16
Own server or LimeSurvey hosting: LimeSurvey Cloud
Survey theme/template: Fruity
==================
Hi everybody,
I was wondering if it was possible to create a customized table containing different questions and values from token.
In particular, we need to create a question like the picture I attached below filled in with:
- the text of the question in the first column
- values from token in the second and third column
- numeric value for the answer in the fourth and fifth column (min and max price)
- menu dropdown in the sixth (and last) column

Is it possible to make it happen?

Looking forward to your ideas and thank you for the feedback!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #228717 by Joffm
Replied by Joffm on topic Customized table with token and questions
Hi,
yes it is possible.
And there are some examples her already.

First you have to decide, if you
  • put the values that are taken from the token in the subquestion text (as they are fixed there is no need to have them in the array cells)
  • use two columns of your array where you preset these values with an equation (and set them to "readonly")

Then you may look for examples here to insert a further header
and the way to insert a drop-down column in an array(numbers) where the rest are text input columns.

As I am a bit busy at the moment, send a lss export of this question.
Later I will send back an example.

Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm. Reason: typos

Please Log in to join the conversation.

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228722 by CarlottaToletti
Replied by CarlottaToletti on topic Customized table with token and questions
Hi Joffm,
Thank you for your answer.

We prefer to use the second one option that you suggest and to use two columns of our array where we can preset these values with an equation.

Please find attached the lss export of our survey.
You'll find three questions:
1) table with token
2) array with numeric values
3) array dropdown.
In the third question, in the menu dropdown we need to view "Up", "Down" and "Stable" instead of numbers.

We should put all these questions in one and view the table as showed above.

Thank you
Carlotta

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228724 by Joffm
Replied by Joffm on topic Customized table with token and questions
Hi, Carlotta,
I already started to create something.

Here you are:
 

And the sample survey
 

File Attachment:

File Name: limesurvey...9549.lss
File Size:36 KB


In the script you see three parts:
1. Insert the drop-down and set the first two columns to "readonly"
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
              <option value="">...</option>\
            <option value="1">increase</option>\
            <option value="2">stay the same</option>\
            <option value="3">decrease</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'
    });
    
    // Set the first two columns to readonly
    $('.answer-item:nth-child(2) input:text', thisQuestion).prop('readonly', true);
    $('.answer-item:nth-child(3) input:text', thisQuestion).prop('readonly', true);
 
  });
</script>

2. Insert the additional header. Adapt to your needs
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
    // Insert the column categories
    $('#question{QID} table.subquestion-list thead tr:eq(0) td:eq(0)').remove();
    $('#question{QID} table.subquestion-list thead').prepend('<tr class="ls-heading">\
      <td rowspan="2" colspan="1" style="border-top:0 !important;font-weight:bold;padding-top:30px;">Products</td>\
      <th class="answer-text inserted-header" colspan="2">14.7.2021</th>\
      <th class="answer-text inserted-header" colspan="2">21.7.2021</th>\
      <th class="answer-text inserted-header" colspan="1">Trends</th>\
    </tr>');
    });    
</script>

3. Adapt the column widths a bit
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);
      });
    });
  });
</script>
Code:
<style type="text/css">.custom-array table.subquestion-list col {
    width: auto !important;
  }
  .custom-array table.subquestion-list thead .column-0 {  width: 20%; }
  .custom-array table.subquestion-list thead .column-1 {  width: 20%; }
  .custom-array table.subquestion-list thead .column-2 {  width: 20%; }
  .custom-array table.subquestion-list thead .column-3 {  width: 40%; }
</style>

Remember: Because of the additional header there are only four columns

At the end something to display the subquestion text left aligned. Looks better in my opinion.

Joffm

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

Please Log in to join the conversation.

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228754 by CarlottaToletti
Replied by CarlottaToletti on topic Customized table with token and questions
Thank you very much Joffm!

We are trying it and it's working

Carlotta

Please Log in to join the conversation.

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228981 by CarlottaToletti
Replied by CarlottaToletti on topic Customized table with token and questions
Hi Joffm,
we are using the solution you suggested and it's working.
However we should be able to enter value from token in the header of the table too because the date is not always the same but changes every week.
How can I put the token in that section? Below you can find your javascript with the date highlighted with red.

<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// Insert the column categories
$('#question{QID} table.subquestion-list thead tr:eq(0) td:eq(0)').remove();
$('#question{QID} table.subquestion-list thead').prepend('<tr class="ls-heading">\
<td rowspan="2" colspan="1" style="border-top:0 !important;font-weight:bold;padding-top:30px;">Products</td>\
<th class="answer-text inserted-header" colspan="2">14.7.2021</th>\
<th class="answer-text inserted-header" colspan="2">21.7.2021</th>\
<th class="answer-text inserted-header" colspan="1">Trends</th>\
</tr>');
});
</script>

Thank you in advanced.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228982 by Joffm
Replied by Joffm on topic Customized table with token and questions
What does this date depend on ?
The respondent?
Add two additional attributes to the token table and use{TOKEN: ATTRIBUTE_1} resp. _2.

The actual date?
Create questions of type equation to calculate the two dates (date1 and date2) and use 
{date1}

Quick response from my smartphone

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

Please Log in to join the conversation.

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #229146 by CarlottaToletti
Replied by CarlottaToletti on topic Customized table with token and questions
Hi Joffm,
thank you for your help. The question we created it's working. We solved the data problem entering the token inside your javascript and it runs.
However when we try to view the question by the phone it looks like different from computer: as you can see in the picture attached it doesn't show the column categories.
Do you know how can we solve this problem?

Thanks in advance

Carlotta
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #229147 by Joffm
Replied by Joffm on topic Customized table with token and questions
This is the usual and desired behaviour of a responsive display.
How do you imagine a display of your five columns horizontally on a smartphone?

Read here
[url] getbootstrap.com/docs/3.4/css/#grid [/url]

 

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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #229158 by Joffm
Replied by Joffm on topic Customized table with token and questions
Hi,
I missed that you referred to this additional header.
Yes, this script is only for desktop.

What you can do, is to check at the start of the survey, whether a smartphone is used.

If "yes",
a. screen out the respondent
b. tell him to continue the survey on a desktop.

c. display a question with a different layout.

d. add the date to the regular header (with an If-statement).

Option d. seems to be the best.
Tomorrow I'll try something.

This was from my smartphone; therefore no more.

​​​​​​Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #229160 by Joffm
Replied by Joffm on topic Customized table with token and questions
Here an example with a check of "mobile", "viewport width", etc.
 

Now you can use these values to customize the display, like
{if(Q0_SQ005 lt 1024,"<span style='font-weight:bold'>" + TOKEN:ATTRIBUTE_7 + "</span>","")} min.

or
{if(Q0_SQ003=="true","<span style='color:red'>" + TOKEN:ATTRIBUTE_7 + "</span>","")} min.

On a small screen the date prepends the "min." resp. "max."
Of course the styling is up to you.

Result:
 

The sample survey:
 

File Attachment:

File Name: limesurvey... (1).lss
File Size:62 KB


Joffm

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

Please Log in to join the conversation.

  • CarlottaToletti
  • CarlottaToletti's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #229178 by CarlottaToletti
Replied by CarlottaToletti on topic Customized table with token and questions
Thank you Joffm,
we solved by changing the columns and entering the date along with min and max.

Have a nice day
Carlotta

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose