Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Multilingual surve: sorting responses alphabetically in a 2nd, 3rd language ?

Multilingual surve: sorting responses alphabetically in a 2nd, 3rd language ? 7 Monate 2 Tage her #107816

  • karld
  • karlds Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 15
  • Karma: 0
Hello,

I have a survey with 2 languages:
  • in the main language, the answers of a question (e.g. multiple choice) are sorted alphabetically (I did it when designing the question)
  • How can I have the answers sorted alphabetically in the second language?

Thanks in advance,

--
Carl
Letzte Änderung: 7 Monate 2 Tage her von karld.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Multilingual surve: sorting responses alphabetically in a 2nd, 3rd language ? 7 Monate 1 Tag her #107852

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4362
  • Dank erhalten: 827
  • Karma: 381
You will need to use a little JavaScript to move those around.

Here's a solution for list-radio and multiple-choice questions

1) Set up your survey to use JavaScript.

2) Add this function to the end of template.js:
function sortOptions(qID) {
 
	// Identify this question
	var thisQuestion = $('#question'+qID);
 
	// Create an array of subquestions
	var subQsArr = new Array();
	$('li.answer-item', thisQuestion).each(function(i) {
		var thisString = $(this).find('.answertext').text()+'---'+$(this).attr('id');
		subQsArr.push(thisString);
	});
 
	// Sort the array
	subQsArr.sort();
 
	// Repostion the subquestions in the sorted order
	$(subQsArr).each(function(i, val) {
		var thisID = val.split('---')[1];
		$('li.answer-item:eq(0)', thisQuestion).parent().append($('#'+thisID));
	});
}

3) Add this script to the source of every question that you want sorted (in all languages to be sorted):
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
		sortOptions({QID});
	});
</script>

.
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Letzte Änderung: 7 Monate 1 Tag her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: karld

Multilingual surve: sorting responses alphabetically in a 2nd, 3rd language ? 7 Monate 10 Stunden her #107883

  • karld
  • karlds Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 15
  • Karma: 0
Thank you very much.

I have tried it on a radio buttons list question, it works fine, but the "other" with a textbox is also sorted.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Multilingual surve: sorting responses alphabetically in a 2nd, 3rd language ? 7 Monate 9 Stunden her #107890

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4362
  • Dank erhalten: 827
  • Karma: 381
Oh, yeah, forgot that. Use this as the function in template.js:
function sortOptions(qID) {
 
	// Identify this question
	var thisQuestion = $('#question'+qID);
 
	// Create an array of subquestions
	var subQsArr = new Array();
	$('li.answer-item', thisQuestion).each(function(i) {
		var thisString = $(this).find('.answertext').text()+'---'+$(this).attr('id');
		subQsArr.push(thisString);
	});
 
	// Sort the array
	subQsArr.sort();
 
	// Repostion the subquestions in the sorted order
	$(subQsArr).each(function(i, val) {
		var thisID = val.split('---')[1];
		$('li.answer-item:eq(0)', thisQuestion).parent().append($('#'+thisID));
	});
	$('li.answer-item:eq(0)', thisQuestion).parent().append($('li.answer-item[id$="other"]', thisQuestion));
}
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: karld

Multilingual survey: sorting responses alphabetically in a 2nd, 3rd language ? 7 Monate 8 Stunden her #107900

  • karld
  • karlds Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 15
  • Karma: 0
Great ! It works as expected.

Many thanks.
Letzte Änderung: 7 Monate 8 Stunden her von karld.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.144 Sekunden
Donation Image