- Posts: 6
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Unique Suffix by Row for an Array Question
- rezyface
- Topic Author
- Offline
- New Member
Less
More
10 years 1 month ago #106814
by rezyface
Unique Suffix by Row for an Array Question was created 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!
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106835
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
This should do the trick for row-specific suffixes.
.
Code:
<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 topic has been locked.
- rezyface
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
10 years 1 month ago #106855
by rezyface
Replied by rezyface on topic Unique Suffix by Row for an Array Question
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!
Any ideas?
Thank you!
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106856
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
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 topic has been locked.
- rezyface
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
10 years 1 month ago #106859
by rezyface
Replied by rezyface on topic Unique Suffix by Row for an Array Question
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
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106862
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
The code I supplied is for LimeSurvey version 2.05. You must be using an older version.
Replace this line:
With this:
.
Replace this line:
Code:
$('#question'+qID+' tr.subquestion-list:eq('+(i-1)+') input[type="text"]').after(this);
With this:
Code:
$('#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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106865
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
I can see that you are still having problems.
What LS version are you using and can you attach an export of that survey?
.
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 topic has been locked.
- rezyface
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
10 years 1 month ago #106866
by rezyface
Replied by rezyface on topic Unique Suffix by Row for an Array Question
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!
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 topic has been locked.
- rezyface
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
10 years 1 month ago #106869
by rezyface
Replied by rezyface on topic Unique Suffix by Row for an Array Question
I have attached the test survey (found in the link above).
Thanks!
Thanks!
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106870
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
10 years 1 month ago #106875
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Unique Suffix by Row for an Array Question
Oops, for 1.92, that line should have bees this:
And you had one small syntax error - this {37581}, should be this {QID}.
Here is a working version:
Code:
$('#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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- rezyface
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
10 years 1 month ago #106881
by rezyface
Replied by rezyface on topic Unique Suffix by Row for an Array Question
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!
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 topic has been locked.