Unique Suffix by Row for an Array Question

More
3 years 15 hours ago #106814 by rezyface
Hi all,

First of all big thank you (Vielen Dank!) to LimeSurvey Dev team!
My question I think is fairly straight forward. We have previously seen that LimeSurvey can be manipulated to add a unique suffix per column for an Array question.
See here:
www.limesurvey.org/en/forum/can-i-do-thi...-multi-flexible-text

However my Javascript knowledge is not sufficient to translate that to be row based instead of column.

For example I would like the array to look like:

Minimum for all Participants Minimum for WIA Participants
Rate of Rentention ___________ % _____________ %
Wages at placement ___________ $ _____________ $

and so on.

Any helpful hints?

Thank you!

Please Log in to join the conversation.

More
3 years 24 minutes ago #106835 by tpartner
This should do the trick for row-specific suffixes.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() {
 
		// Call the function with the question ID followed by a comma-separated list of suffixes
		addSuffixByRow({QID}, '%', '$', 'hours', 'km');
 
		// Function to add row-specific suffixes to an array
		function addSuffixByRow() {
 
			var qID = $(arguments)[0];
 
			// Some styling
			$('#question'+qID+' input[type="text"]').css({
				'width': '50%'
			});
 
			// Insert the suffixes
			$(arguments).each(function(i, val){
				if(i > 0) {
					$('#question'+qID+' tr.subquestion-list:eq('+(i-1)+') input[type="text"]').after(this);
				}
			});
		}
	});
</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
2 years 11 months ago #106855 by rezyface
Thank you so much for the quick response! Unfortunately, while the input boxes are being resized appropriately the actual suffixes are not being added. I have inserted an "alert" statement into the if(i >0) statement in your code below and I do get 4 "alert" messages so we are iterating correctly. I am using an "Array Numbers" question type. I have added a screenshot for you to see the question.

Any ideas?

Thank you!

Attachments:

Please Log in to join the conversation.

More
2 years 11 months ago #106856 by tpartner
Please activate a sample survey so I can see the source code.

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
2 years 11 months ago #106859 by rezyface
Hello,
Here is a test link with just the 1 question plus your code. As you will note, the text input boxes have widened appropriately but the suffixes have not been added.

Thank you!

survey.altarum.org/limesurvey/index.php?sid=11978&lang=en

Please Log in to join the conversation.

More
2 years 11 months ago #106862 by tpartner
The code I supplied is for LimeSurvey version 2.05. You must be using an older version.

Replace this line:
$('#question'+qID+' tr.subquestion-list:eq('+(i-1)+') input[type="text"]').after(this);

With this:
$('#question'+qID+' tbody[id^="javatbd"]:eq('+(i-1)+') input[type="text"]').after(this);


.

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
2 years 11 months ago #106865 by tpartner
I can see that you are still having problems.

What LS version are you using and can you attach an export of that survey?


.

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
2 years 11 months ago #106866 by rezyface
Hi,
Sorry the Lime version should have been the first thing mentioned. Using version 1.92+ Build 120909.

I replaced the line as you had said but still "no potatoes". The link above is still active and reflects the altered code.

So sorry for the hassle. Appreciate any guidance you may give.

Vielen Dank!

Please Log in to join the conversation.

More
2 years 11 months ago #106869 by rezyface
I have attached the test survey (found in the link above).

Thanks!
Attachments:

Please Log in to join the conversation.

More
2 years 11 months ago #106870 by tpartner
Can you attach an export of that survey?

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
2 years 11 months ago #106875 by tpartner
Oops, for 1.92, that line should have bees this:
$('#question'+qID+' tbody[id^="javatbd"]:eq('+(i-1)+') input[type="text"]').after(val);

And you had one small syntax error - this {37581}, should be this {QID}.

Here is a working version:

File Attachment:

File Name: limesurvey...1978.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:

Please Log in to join the conversation.

More
2 years 11 months ago #106881 by rezyface
Thank you so much! Working like a charm now!

Do you have any specific website / book in mind that you would recommend for learning Javascript? Any website/book that would focus on Javascript as it applies to LimeSurvey?

My background: I use SAS professionally (been writing SAS programs that interact with the LimeSurvey SQL tables - quite fun) and I know a little Java as well as a much smaller amount of Perl. My HTML / JS knowledge is unfortunately minimal and any JS I have used in previous Lime surveys has been done by scouring the forums / manual and editing/testing copied code to make it work for my purposes.

Again, big thank you for your time!

Please Log in to join the conversation.

More
2 years 11 months ago #106883 by DenisChenu

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.