Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Unique Suffix by Row for an Array Question

Unique Suffix by Row for an Array Question 2 years 5 months ago #106814

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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!
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106835

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106855

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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!

The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106856

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106859

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106862

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106865

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106866

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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!
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106869

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
I have attached the test survey (found in the link above).

Thanks!
Attachments:
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106870

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106875

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6221
  • Thank you received: 1379
  • Karma: 539
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.
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106881

  • rezyface
  • rezyface's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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!
The administrator has disabled public write access.

Unique Suffix by Row for an Array Question 2 years 5 months ago #106883

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9305
  • Thank you received: 1330
  • Karma: 386
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.548 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form