Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Changing a column of an array (number) type question to text input

Changing a column of an array (number) type question to text input 10 Monate 4 Tage her #102534

  • limejohn
  • limejohns Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 4
  • Karma: 0
I have an array numbers with drop downs, but there are two questions within the array that should be text inputs and not a value to be selected from a dropdown. I haven´t been able to figure out how to change them using javascript. I tried looking in the forum at similar topics, but none of the suggested answers were for this specific type of array.

Can this be done? and if so, any tips on how to do it?
Anhang:
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Changing a column of an array (number) type question to text input 10 Monate 4 Tage her #102544

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4264
  • Dank erhalten: 801
  • Karma: 368
I think the only solution would be to add some following multiple-short-text questions and then use JavaScript to hide those questions and move their text inputs into the array.

Some insights on how to do that here - www.limesurvey.org/en/forum/can-i-do-thi...ution?start=20#91170
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.

Changing a column of an array (number) type question to text input 10 Monate 4 Tage her #102547

  • limejohn
  • limejohns Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 4
  • Karma: 0
i have already edited my array quite a bti to get variable dropdowns and to hide some things, I tried to incorporate your code but i was not successful so i´m not sure exactly what you are doing in your code

Are you just creating an additional short text question and then adding a column to the array and replacing it with the blank text from the additional question?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Changing a column of an array (number) type question to text input 10 Monate 4 Tage her #102550

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4264
  • Dank erhalten: 801
  • Karma: 368
In your case, I would add two multiple-short-text questions and then have the JavaScript:
1) Hide those questions
2) Insert 2 new columns in the array
3) Move the text inputs from the hidden questions into the new array columns

So, this script added to the source of the array should do the trick:
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// Identify the questions
		var thisQuestion = $('#question{QID}');
		var nextMultiText1 = $(thisQuestion).nextAll('.multiple-short-txt:eq(0)');
		var nextMultiText2 = $(thisQuestion).nextAll('.multiple-short-txt:eq(1)');
 
		// Hide the next questions 
		$(nextMultiText1).hide();
		$(nextMultiText2).hide();
 
		// Add extra columns to the array
		$('table.question thead tr th:eq(2)', thisQuestion).after('<th class="newColumn1" />');
		$('table.question thead tr th:eq(4)', thisQuestion).after('<th class="newColumn2" />');
		$('table.question tbody tr', thisQuestion).each(function(i) {
			$('td:eq(2)', this).after('<td class="newColumn1" />');
			$('td:eq(4)', this).after('<td class="newColumn2" />');
		});
 
		// Move the hidden question text to the inserted columns
		$('table.question thead tr th.newColumn1', thisQuestion).text($('.questiontext', nextMultiText1).text());
		$('table.question thead tr th.newColumn2', thisQuestion).text($('.questiontext', nextMultiText2).text());
 
		// Move the text inputs and dropdowns
		$('input.text', nextMultiText1).each(function(i){
			$('table.question tbody tr:eq('+i+') td.newColumn1', thisQuestion).append(this);
		});
		$('input.text', nextMultiText2).each(function(i){
			$('table.question tbody tr:eq('+i+') td.newColumn2', thisQuestion).append(this);
		});
 
		// Some cleanup styles (for the default template)
		$('col', thisQuestion).css({
			'width': 'auto'
		});
		$('table.question tbody th, table.question tbody td', thisQuestion).css({
			'padding': '4px 10px'
		});
 
	});
</script>


Here's a working example:

Dateianhang:

Dateiname: limesurvey_survey_966293.lss
Dateigröße: 25 KB
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: limejohn, Gloria

Changing a column of an array (number) type question to text input 5 Monate 1 Woche her #108345

  • Gloria
  • Glorias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 8
  • Karma: 0
Thanks Tony!
Appreciate your help.
I will try this out.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.180 Sekunden
Donation Image