Partially randomized answers (list radio type) in 2.50

More
1 year 5 months ago - 1 year 5 months ago #138854 by tarantel999
tarantel999 created the topic: Partially randomized answers (list radio type) in 2.50
For some reason the code that has worked on previous version doesn't seem to do that on 2.50. What should I do differently?
Is there a working solution for this?

manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29


<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 = 2;
 
		// Identify this question
		var qID = {QID}; 
 
		// Find the number of answers
		var ansCount = $('#question'+qID+' li.answer-item').length;
 
		// 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$="X'+qID+(ansCount-fixedIndex)+'"]');
			var answerItem = $(answer).closest('li');
			var answersList = $(answer).closest('ul');
			$(answersList).append(answerItem);
			fixedIndex--;
		}		
	});
</script>
Last Edit: 1 year 5 months ago by tarantel999.

Please Log in to join the conversation.

More
1 year 5 months ago #138876 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
In LimeSurvey 2.50, you need to use this script:

<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 = 2;
 
		// Identify this question
		var qID = {QID}; 
 
		// Find the number of answers
		var ansCount = $('#question'+qID+' .answer-item').length;
 
		// 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('.answers-list');
			if($('#question'+qID).hasClass('multiple-opt')) {
				answerItem = $(answer).closest('.answer-item').parent();
				answersList = $(answer).closest('.subquestion-list');
			}
			$(answersList).append(answerItem);
			fixedIndex--;
		}		
	});
</script>

I have updated the workaround accordingly - 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.
The following user(s) said Thank You: vkuzmin

Please Log in to join the conversation.

More
1 year 4 months ago #139218 by gyts
gyts replied the topic: Partially randomized answers (list radio type) in 2.50
Hi, thanks for all your help. It seems that i cannot make work this. I upload the example file and it doenst work. Maybe its a server problem or something that i have to change in the code.

Please Log in to join the conversation.

More
1 year 4 months ago #139221 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
Did you import the correct file? There is one for 2.06 and another for 2.5. Do you have any JavaScript errors in the console?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
1 year 4 months ago #139228 by gyts
gyts replied the topic: Partially randomized answers (list radio type) in 2.50

I downloaded the 2.5 file. And theres nothing in the console. Its weird. Maybe its a setting on the app or the template You have to change something in the script to work? (qid?)
Attachments:

Please Log in to join the conversation.

More
1 year 4 months ago #139229 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
Can you activate that survey and give a link?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
1 year 4 months ago #139230 by gyts
gyts replied the topic: Partially randomized answers (list radio type) in 2.50

Please Log in to join the conversation.

More
1 year 4 months ago - 1 year 4 months ago #139232 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
The workaround instructions say 'The "Show No answer" survey setting must be set to "No" ' - 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: 1 year 4 months ago by tpartner.

Please Log in to join the conversation.

More
10 months 3 weeks ago #147457 by gyts
gyts replied the topic: Partially randomized answers (list radio type) in 2.50
Im again with this problem. I change the server and cannot do it. I had imported the example and doest work.
Could you help me please?
gyts.ga/index.php/874188?lang=en

Please Log in to join the conversation.

More
10 months 3 weeks ago #147468 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
You're not using the 2.50 script.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
10 months 3 weeks ago #147469 by gyts
gyts replied the topic: Partially randomized answers (list radio type) in 2.50
im so stupid. I missread. Im sorry pal, thank for the patience

Please Log in to join the conversation.

More
2 weeks 5 days ago #160906 by blocka
blocka replied the topic: Partially randomized answers (list radio type) in 2.50
I cannot get this to work on a list type (radio) question. It works fine when using multiple choice.

I've attached my LSS -- using LS version 2.72.4 build 171110

Can anyone help?
Attachments:

Please Log in to join the conversation.

More
2 weeks 5 days ago #160907 by tpartner
tpartner replied the topic: Partially randomized answers (list radio type) in 2.50
In that version, the IDs have changed slightly - use this script:

<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 = 2;
 
		// Identify this question
		var qID = {QID}; 
 
		// Find the number of answers
		var ansCount = $('#question'+qID+' .answer-item').length;
 
		// Place the last n answers created at the end of the list
		var fixedIndex = fixedAnswers - 1;
		for (var i=0; i<fixedAnswers; i++) {
			var answerItem = $('.answer-item[id^="javatbd"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
			if($('#question'+qID).hasClass('multiple-opt')) {
				$(answerItem).closest('.subquestion-list').append($(answerItem).parent());
			}
			else {
				$(answerItem).closest('.answers-list').append(answerItem);
			}
			fixedIndex--;
		}		
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...9124.lss
File Size:19 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: blocka

Please Log in to join the conversation.

More
2 weeks 5 days ago #160908 by blocka
blocka replied the topic: Partially randomized answers (list radio type) in 2.50
Awesome! Thanks so much, I've confirmed it works :-)

Please Log in to join the conversation.

More
1 week 2 days ago #161249 by first
first replied the topic: Partially randomized answers (list radio type) in 2.50
I am back on forums after a long time :) . Here is my try:

This will go in template.js
function keepPos(SGQ,posArr){
    var qtype = '';
	var qid = SGQ.split('X')[2];
	var $thisq = $('#question'+qid+'');
	if($thisq.hasClass('multiple-opt')){
		qtype = 'multiple-opt';		
	}else if($thisq.hasClass('list-radio')){
		qtype = 'list-radio';	
	}
 
	for (var i = posArr.length - 1; i >= 0; --i) {
		var thisPair = posArr[i].split('|');
		var $allAnsItems = '';
		var $thisAnsItem = '';
		if(qtype == 'multiple-opt'){
			$thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+'').parent();
			$allAnsItems = $('.answer-item',$thisq).parent();
		}else if(qtype == 'list-radio'){
			$thisAnsItem = $('#javatbd'+SGQ+''+thisPair[0]+'');
			$allAnsItems = $('.answer-item',$thisq);
		}
		$allAnsItems.eq(thisPair[1] - 1).after($thisAnsItem);
	}
 
}

and this will go in question text.
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
		keepPos('{SGQ}',['SQ006|6','SQ007|7']) //	keepPos('{SGQ}',['code|position','code|position'])
	});
</script>

tested with Version 2.72.5 and list-radio and multi-checkbox.

Survey Designer and Programmer

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!