Welcome to the LimeSurvey Community Forum

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

Slider and Comment Box (or text question) combination

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #226229 by boshra.m
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud Version 5.2.13
Own server or LimeSurvey hosting:
Survey theme/template: Fruity
==================
Hi,

I was wondering if anyone knew if it was possible to have a slider question and right next to each sub-question (or even right below them) have a text question (ie. a place where individuals can write their comments)?

I was able to do this by combining an array question and a multiple short text question by using the following code (below) in the source of the array question, but I am unsure of how to combine an a slider question (multiple numerical input) with a multiple short text question. 

<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();
 
    var tableWidth = $('table.questions-list:eq(0)', qArray).width();
    var answerWidth = $('col.ls-col-odd:eq(0)', qArray).width();
    var answerWidthPercent = (answerWidth/tableWidth)*100;
    var answersLength = $('col.ls-col-odd, col.ls-col-even', qArray).length;
    var answerWidthPercent2 = (answerWidthPercent*answersLength)/(answersLength+1)
    $('table.questions-list col', qArray).removeAttr('width');
    $('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>

I have also read this manual but I think I am missing something. I hope I am making sense! 

Thank you!!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226251 by tpartner
Can you attach a small sample survey (.lss file) containing only the relevant questions?

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: boshra.m

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #226260 by boshra.m
Hi,

For sure! I have attached a small sample survey (.iss) of 2 questions below. 

Thank you!



 

File Attachment:

File Name: Test-Sliders.lss.txt
File Size:49 KB

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226272 by tpartner
This script will move the text inputs from a following multiple-short-text question into the sub-questions of a multiple-numeric question:

Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).nextAll('.multiple-short-txt:eq(0)');
 
    // Hide the next question
    $(nextQuestion).hide();
 
    // Loop through the multi-numeric sub-questions
    $('li.answer-item', thisQuestion).each(function(i) {
      // Move the corresponding text input
      console.log($('.answer-item:eq('+i+') > div', nextQuestion));
      $('.answer-item:eq('+i+') > div', nextQuestion).removeClass('col-xs-12 col-sm-8').addClass('text-item').appendTo($('> div', this));
    });
 
    // Cleanup styles
    $('.text-item', thisQuestion).css({
      'padding': '10px',
      'clear': 'both'
    });
 
  });
</script>



Sample survey attached: 

File Attachment:

File Name: limesurvey...6489.lss
File Size:50 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: boshra.m

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #226278 by boshra.m
This is awesome, thank you!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose