Welcome to the LimeSurvey Community Forum

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

Multi-Array dual scale

  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 3 months ago #179431 by Olegna001
Multi-Array dual scale was created by Olegna001
Hi, I’m new to Lime Survey, but doing lots of reading at the moment. I have a challenge to solve.

Can anyone tell me if it is possible to create an Array Dual Scale with multiple fields (not just 2)?

If this is possible, please share your solution?

To explain it further; I’m trying to create a question group. Each question is different, but the sub-questions for each is the same. And to answer the sub-questions I would like to provide the user with drop downs with preset answer options.

Example:

Question Group = Tennis

Q1 = Playing Tennis
Sub Q1a = Do you play? (Drop down = Yes; No)
Sub Q1b = How often?
(Drop down = Daily, Weekly, Monthly)
Sub Q1c = How much time per session (Drop down = 30 min; 45 min; 1 hr; 1:5 hr; 2 hrs; 2.5 hrs or more)

Question Group = Squash
Q2 = Playing Squash
same sub questions as above

Question Group = Golf
Etc...etc...

Appreciate your help.

Also, is it possible to create this solution without custom code? If not, that’s ok, just trying to look for the easiest way to solve this challenge.

Thanks,
AG
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179442 by tpartner
Replied by tpartner on topic Multi-Array dual scale
You may be able to adapt this workaround to your needs.

- www.limesurvey.org/forum/can-i-do-this-w...list?start=15#173576

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 2 months ago #179448 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony,

Thanks. I've imported your solution to review and test out. It's great; the general idea is right, however, how do I switch it around? (i.e. I need consistent drop-downs populating down the columns, not across as rows)? Appreciate your help. Apologies, coding isn't my best skill.


Thanks,
AG
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179468 by tpartner
Replied by tpartner on topic Multi-Array dual scale
This example will insert consistent drop-downs in columns:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Column specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i);
      });
    });
 
    // Insert selects into column 1
    if($('.answer-item.column-1 .inserted-select', thisQuestion).length == 0) {
      $('.answer-item.column-1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
        <option value="">Please choose...</option>\
        <option value="1">Yes</option>\
        <option value="2">No</option>\
        <option value="3">Do not know</option>\
      </select>');
    } 
 
    // Insert selects into column 2
    if($('.answer-item.column-2 .inserted-select', thisQuestion).length == 0) {
      $('.answer-item.column-2', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
        <option value="">Please choose...</option>\
        <option value="1">Red</option>\
        <option value="2">Blue</option>\
        <option value="3">Pink</option>\
        <option value="3">Purple</option>\
      </select>');  
    } 
 
    // Listeners on select elements
    $('.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>



Sample survey attached:

File Attachment:

File Name: limesurvey...1223.lss
File Size:28 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Olegna001
The topic has been locked.
  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 2 months ago #179570 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony, this is just what I needed. Works perfectly and I have been able to adapt the code for my needs. Thanks very much!
The topic has been locked.
  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 2 months ago #179571 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Another few questions Tony:
1. How do I make column 1 mandatory to force the user to select either Yes or No?
2. And also, if they select Yes, the remaining columns in that row should be mandatory also, but if they select No, they do not need to complete the remaining columns.
3. Lastly, for the very first column, that does not have a heading, how do I add tooltips for each row?

I believe all of the above can be done through the UI editor, but now as I am dealing with custom code, I assume I need to modify the code to enable this functionality?

Really appreciate your help.

Thanks,
Angelo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179684 by tpartner
Replied by tpartner on topic Multi-Array dual scale
1. & 2. This can be done with a question validation equation like this:

Code:
(that.Q1.sq_Y001_X001 == 'Yes' OR (that.Q1.sq_Y001_X001 == 'No' AND count(that.Q1.sq_Y001) == 4))
AND
(that.Q1.sq_Y002_X001 == 'Yes' OR (that.Q1.sq_Y002_X001 == 'No' AND count(that.Q1.sq_Y002) == 4))
AND
(that.Q1.sq_Y003_X001 == 'Yes' OR (that.Q1.sq_Y003_X001 == 'No' AND count(that.Q1.sq_Y003) == 4))
AND
(that.Q1.sq_Y004_X001 == 'Yes' OR (that.Q1.sq_Y004_X001 == 'No' AND count(that.Q1.sq_Y004) == 4))


3. In LimeSurvey 3.x, you can use Bootstrap Tooltips . So, something like this in the sub-question text:

Code:
<a href="#" data-toggle="tooltip" title="" data-original-title="Tooltip content 1">this has a tooltip</a>



Sample survey attached:

File Attachment:

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Olegna001
The topic has been locked.
  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 2 months ago #179792 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony,

This is fantastic, thanks very much for your help. Through your support, I’m really enjoying the use of this tool & learning a lot.

One more question if you don’t mind:

4. Is it possible to hide or make the first column (I.e. column 0 in your example above without a heading) width smaller, or so that it adapts to the width of the text contents? For some tables it makes sense to have the first column visible, but for others I don’t need it. Appreciate if you could tell me both methods (I.e. hide completely, or make the width fits cell contents)

Thanks again for your support!

Cheers,
Angelo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179812 by tpartner
Replied by tpartner on topic Multi-Array dual scale
There is a question setting for the sub-question width - manual.limesurvey.org/Question_type_-_Ar...subquestion_width.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Olegna001
The topic has been locked.
  • Olegna001
  • Olegna001's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 2 months ago #179833 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Brilliant! Found the setting. Works like a gem - thanks again Tony!

Cheers,
Angelo
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose