Welcome to the LimeSurvey Community Forum

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

Fixed answer options in list+multi

  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 years 1 week ago #167234 by Matadeleo
Fixed answer options in list+multi was created by Matadeleo
Hi,

I'm trying to fix answer options at the bottom of a list and while it is working for multi-choice, it isn't working for single choice (list-radio) questions.

I've attached an example survey, and I'm using the code given on the LimeSurvey workarounds page.

I've tested in version 2.50+ and 3.6.2.

File Attachment:

File Name: fixedanswe...ions.lss
File Size:22 KB
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 week ago #167247 by Joffm
Replied by Joffm on topic Fixed answer options in list+multi
Hi,

the forums search is your friend:

here the solution:
www.limesurvey.org/forum/can-i-do-this-w...?limitstart=0#160907


or use this from the workaround section for V2.73
manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // The number of answers to be fixed at the end of the list
    var fixedAnswers = 1;
 
    // Set this to "true" if you want "Other" to be fixed in the last position
    var otherFixed = false;
 
    // Identify this question
    var qID = {QID}; 
 
    // Find the number of answers
    var ansCount = $('#question'+qID+' .answer-item').length;
    if($('#question'+qID+' input[type="text"]').length > 0) {
      ansCount = ansCount -1
    }
 
    // Place the last n answers created at the end of the list
    var fixedIndex = fixedAnswers - 1;
    for (var i=0; i<fixedAnswers; i++) {
      var answer = $('input[id^="answer"][id$="X'+qID+'s'+(ansCount-fixedIndex)+'"]');
      var answerItem = $(answer).closest('.answer-item');
      var answersList = $(answer).closest('.answers-list');
      if($('#question'+qID).hasClass('multiple-opt')) {
        answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
        answerItem = $(answer).closest('.answer-item').parent();
        answersList = $(answer).closest('.subquestion-list');
      }
      $(answersList).append(answerItem);
      fixedIndex--;
    }    
 
    // Handle "Other"
    if(otherFixed == true &amp;&amp; $('#question'+qID+' input[type="text"]').length > 0) {
      var otherAnswer = $('#question'+qID+' input[type="text"]');
      var otherAnswerItem = $(otherAnswer ).closest('.answer-item');
      var otherAnswersList = $(otherAnswer ).closest('.answers-list');
      if($('#question'+qID).hasClass('multiple-opt')) {
        otherAnswerItem = $(otherAnswer ).closest('.answer-item').parent();
        otherAnswersList = $(otherAnswer ).closest('.subquestion-list');
      }
      $(otherAnswersList).append(otherAnswerItem);
    }
  });
</script>

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 years 1 week ago #167248 by Matadeleo
Replied by Matadeleo on topic Fixed answer options in list+multi
Hi Joffm,

Thanks. I did use the search function and found my way to the 2.73 solution (which unfortunately doesn't appear to work in 3.6.2?)

But the 2.50 version worked great. Hopefully I can find a version of that code which is working at 3.6.2+!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 6 days ago #167275 by tpartner
Replied by tpartner on topic Fixed answer options in list+multi
Can you attach a small sample survey for 3.x including the code that you are trying?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 years 6 days ago - 6 years 6 days ago #167293 by Matadeleo
Replied by Matadeleo on topic Fixed answer options in list+multi
Here is a copy with version 3.6.2

Now I hope there isn't a stupid mistake I made to embarass me :P

File Attachment:

File Name: fixedanswe...V362.lss
File Size:22 KB
Last edit: 6 years 6 days ago by Matadeleo.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 6 days ago - 6 years 6 days ago #167325 by tpartner
Replied by tpartner on topic Fixed answer options in list+multi
No mistakes at all - the HTML structure has been changed (again).

This is the script for LS version 3.x:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // The number of answers to be fixed at the end of the list
    var fixedAnswers = 1;
 
    // Set this to "true" if you want "Other" to be fixed in the last position
    var otherFixed = false;
 
    // Identify this question
    var qID = {QID}; 
 
    // Find the number of answers
    var ansCount = $('#question'+qID+' .answer-item').length;
    if($('#question'+qID+' input[type="text"]').length > 0) {
      ansCount = ansCount -1
    }
    console.log(ansCount);
 
    // Place the last n answers created at the end of the list
    var fixedIndex = fixedAnswers - 1;
    for (var i=0; i<fixedAnswers; i++) {
      var answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
      var answerItem = $(answer).closest('.answer-item');
      var answersList = $(answer).closest('ul');
      $(answersList).append(answerItem);
      fixedIndex--;
    }    
 
    // Handle "Other"
    if(otherFixed == true &amp;&amp; $('#question'+qID+' input[type="text"]').length > 0) {
      var otherAnswer = $('#question'+qID+' input[type="text"]');
      var otherAnswerItem = $(otherAnswer ).closest('.answer-item');
      var otherAnswersList = $(otherAnswer ).closest('ul');
      $(otherAnswersList).append(otherAnswerItem);
    }
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3199.lss
File Size:22 KB


I have updated the workaround - manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 6 days ago by tpartner.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 years 3 days ago #167348 by Matadeleo
Replied by Matadeleo on topic Fixed answer options in list+multi
Thanks tpartner B)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose