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

More
3 years 6 months ago #102534 by limejohn
limejohn created the topic: Changing a column of an array (number) type question to text input
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?
Attachments:

Please Log in to join the conversation.

More
3 years 6 months ago #102544 by tpartner
tpartner replied the topic: Changing a column of an array (number) type question to text input
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.

Please Log in to join the conversation.

More
3 years 6 months ago #102547 by limejohn
limejohn replied the topic: Changing a column of an array (number) type question to text input
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?

Please Log in to join the conversation.

More
3 years 6 months ago #102550 by tpartner
tpartner replied the topic: Changing a column of an array (number) type question to text input
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:

File Attachment:

File Name: limesurvey...6293.lss
File Size:25 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: limejohn, Gloria01

Please Log in to join the conversation.

More
3 years 1 month ago #108345 by Gloria01
Gloria01 replied the topic: Changing a column of an array (number) type question to text input
Thanks Tony!
Appreciate your help.
I will try this out.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now