Quantcast
Channel: Topics in Category: Can I do this with LimeSurvey? - LimeSurvey forums
Viewing all articles
Browse latest Browse all 17529

Sort Multiple Choice subquestions - by: tpartner

$
0
0
This script should handle columns (in version 2.65.x):

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// Define column and items counts
		var itemsCount = $('.answer-item', thisQuestion).length;
		var columnsCount = $('.multiple-choice-container div.row', thisQuestion).length;
		if(columnsCount > 1) {
			var maxPerColumn = $('.multiple-choice-container div.row:eq(0) .answer-item', thisQuestion).length;
		}
 
		// Build an array of the sub-question texts
		var sqTexts = [];
		$('.label-text', thisQuestion).each(function(i) {
			sqTexts.push($.trim($(this).text()));
		});
 
		// Sort the array
		sqTexts.sort();
 
		// Insert the sub-questions in sorted order
		var currentCount = 1;
		var columnNumber = 0;
		$(sqTexts).each(function(i, value) {
			if(columnsCount < 1) {
				$('.label-text', thisQuestion).filter(function(e) {
					return $.trim($(this).text()) === value;
				}).closest('.answer-item').parent().appendTo($('.multiple-choice-container', thisQuestion));
			}
			else {
				$('.label-text', thisQuestion).filter(function(e) {
					return $.trim($(this).text()) === value;
				}).closest('.answer-item').parent().appendTo($('.multiple-choice-container div.row:eq('+columnNumber+')', thisQuestion));
 
				currentCount++;
				if(currentCount > maxPerColumn) {
					currentCount = 1;
					columnNumber++;
				}
			}
		});
	});
</script>

Viewing all articles
Browse latest Browse all 17529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>