- Posts: 107
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Fixed answer options in list+multi
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
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.
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.
Attachments:
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12922
- Thank you received: 3977
6 years 1 week ago #167247
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
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
Joffm
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 && $('#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
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 107
- Thank you received: 4
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+!
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
6 years 1 week ago #167275
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 107
- Thank you received: 4
6 years 1 week ago - 6 years 1 week 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
Now I hope there isn't a stupid mistake I made to embarass me
Attachments:
Last edit: 6 years 1 week ago by Matadeleo.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
6 years 1 week ago - 6 years 1 week ago #167325
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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:
Sample survey attached:
I have updated the workaround - manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
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 && $('#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:
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.
Attachments:
Last edit: 6 years 1 week ago by tpartner.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
- Matadeleo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 107
- Thank you received: 4
6 years 1 week ago #167348
by Matadeleo
Replied by Matadeleo on topic Fixed answer options in list+multi
Thanks tpartner
The topic has been locked.