- Posts: 18
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
how to add list of survey participants as possible answers for each question
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
6 years 4 months ago #160249
by digitaldust
how to add list of survey participants as possible answers for each question was created by digitaldust
I am trying to build a simple survey that will be sent to a specific group of people. For each question I have, I'd like to list the names of the people in the group as possible answers.
A use case could be:
Question: Who is your friend?
Answers: Simo
Mike
Jack
Ideally, it will be a searchable text field that lists the correct names as you type...
Of course, the list of people is known in advance and always the same for all the questions.
I don't think LimeSurvey offers this option out of the box, and I'd like to know what would be the correct way to put something like this in place. Any pointer to demo articles or pieces of code much appreciated, I am really a newbie here.
A use case could be:
Question: Who is your friend?
Answers: Simo
Mike
Jack
Ideally, it will be a searchable text field that lists the correct names as you type...
Of course, the list of people is known in advance and always the same for all the questions.
I don't think LimeSurvey offers this option out of the box, and I'd like to know what would be the correct way to put something like this in place. Any pointer to demo articles or pieces of code much appreciated, I am really a newbie here.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12714
- Thank you received: 3926
6 years 4 months ago #160250
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic how to add list of survey participants as possible answers for each question
Thre is a workaround in the manual:
manual.limesurvey.org/Workarounds:_Manip...wers_for_text_inputs
with several options.
I suppose there are not too much names, so the first option should be fine.
Regards
Joffm
manual.limesurvey.org/Workarounds:_Manip...wers_for_text_inputs
with several options.
I suppose there are not too much names, so the first option should be fine.
Regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: digitaldust
The topic has been locked.
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 1
6 years 4 months ago #160252
by digitaldust
Replied by digitaldust on topic how to add list of survey participants as possible answers for each question
it seems precisely what I need! I still don't know how to modify the pages and add js, but that should be easy to find online.
Thanks!
Thanks!
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12714
- Thank you received: 3926
6 years 4 months ago - 6 years 4 months ago #160254
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic how to add list of survey participants as possible answers for each question
In the manual it's explained step by step.
And it's really sufficient to add this script in the question text:
and optionally a little bit of styling.
I used:
Regards
Joffm
And it's really sufficient to add this script in the question text:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qID = 1; // You have to adapt to your quetion number $('#question'+qID+' input[type="text"]').autocomplete({ minLength: 2, // This line is optional, signifies number of keystrokes before autocomplete is initiated source: ["John","Bill","Edward","Marvin","Colin"] }); }); </script>
and optionally a little bit of styling.
I used:
Code:
<style type="text/css">.form-horizontal .control-label { margin-bottom: 0; padding-top: 11px; text-align: left; } .ui-autocomplete { width:300px !important; } </style>
Regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 4 months ago by Joffm.
The following user(s) said Thank You: Joshi
The topic has been locked.
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 1
6 years 4 months ago #160257
by digitaldust
Replied by digitaldust on topic how to add list of survey participants as possible answers for each question
thanks for the help, I followed step by step, but with no luck. I have my template, added the .js to it, the resources are loaded fine, no errors in the console, but nothing happens.
I have also tried to add your code to my question, but nothing happens, no error messages... I think I am missing something here...
I have also tried to add your code to my question, but nothing happens, no error messages... I think I am missing something here...
The topic has been locked.
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 1
6 years 4 months ago #160258
by digitaldust
Replied by digitaldust on topic how to add list of survey participants as possible answers for each question
one thing that is not clear to me from the manual is where you have to put the CSV file... can you please advise? thanks
The topic has been locked.
- tpartner
- Online
- LimeSurvey Community Team
Less
More
- Posts: 10612
- Thank you received: 3691
6 years 4 months ago #160259
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 how to add list of survey participants as possible answers for each question
Joffm's example does not use a CSV file, it uses a hard-coded array of names.
Here's a shortened version of his script where you don't need to worry about modifying the QID:
And, attached a sample survey:
Here's a shortened version of his script where you don't need to worry about modifying the QID:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#question{QID} input[type="text"]').autocomplete({ minLength: 2, // This line is optional, signifies number of keystrokes before autocomplete is initiated source: ["John Lennon","John Doe","Bill Gates","Billy Idol","Bill Clinton"] }); }); </script>
And, attached a sample survey:
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.
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 1
6 years 4 months ago #160263
by digitaldust
Replied by digitaldust on topic how to add list of survey participants as possible answers for each question
yes I was referring to the manual in my second post, where there are instructions on how to use a csv file to add possible names... but thanks for your sample survey, it works also in my setting... btw, would that be possible to have more than one selection? it looks like it allows to pick just one name, while I need multiple - and sorry, I didn't specify it at the beginning.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12714
- Thank you received: 3926
6 years 4 months ago #160266
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic how to add list of survey participants as possible answers for each question
Hello,
I wrote "I suppose there are not too much names, so the first option should be fine."
And in the manual this is the option with fixed array.
Okay,
you see that in the script there is a reference to "input[type="text"]"
So it should work with all questions with text fields.
In my screenshot I used an array(text) with two columns.
What do you use?
Multiple short texts?
Best regards
Joffm
I wrote "I suppose there are not too much names, so the first option should be fine."
And in the manual this is the option with fixed array.
In my array there are about 80 different names.1. Plain text input (the easiest, suitable for small lists or arrays).
2. Input from CSV file (a little trickier, requires several files. Suitable for larger lists and arrays).
3. Input from a MySQL database (trickiest, but also the most versatile and secure).
Okay,
you see that in the script there is a reference to "input[type="text"]"
So it should work with all questions with text fields.
In my screenshot I used an array(text) with two columns.
What do you use?
Multiple short texts?
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- digitaldust
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 1
6 years 4 months ago #160267
by digitaldust
Replied by digitaldust on topic how to add list of survey participants as possible answers for each question
I was using a long text and it didn't work, then I switched to short text field and yes, the solution with a csv is working fine now.
I am trying to switch to multiple short text now, since I need to have more than one name selected and it looks like with the short text it's not possible to have more than one.
I am trying to switch to multiple short text now, since I need to have more than one name selected and it looks like with the short text it's not possible to have more than one.
The topic has been locked.
- tpartner
- Online
- LimeSurvey Community Team
Less
More
- Posts: 10612
- Thank you received: 3691
6 years 4 months ago #160268
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 how to add list of survey participants as possible answers for each question
No, the autocomplete plugin only allows one selection.
If you need several names, I would...
1) Use a multiple-short-text question
2) Add this script which includes a trigger for Expression Manager when the text inputs are changed:
3) Give the question a validation equation like this to ensure that answers are unique:
4) Give the question a validation tip something like this:
Sample survey attached:
If you need several names, I would...
1) Use a multiple-short-text question
2) Add this script which includes a trigger for Expression Manager when the text inputs are changed:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#question{QID} input[type="text"]').autocomplete({ minLength: 2, // This line is optional, signifies number of keystrokes before autocomplete is initiated source: ["John Lennon","John Doe","Bill Gates","Billy Idol","Bill Clinton"], change: function(event, ui) { $(this).trigger('keyup'); } }); }); </script>
3) Give the question a validation equation like this to ensure that answers are unique:
Code:
unique(self)
4) Give the question a validation tip something like this:
Code:
{if(unique(self), '', 'Answers must be unique!')}
Sample survey attached:
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: Joshi, digitaldust
The topic has been locked.
- Joshi
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
6 years 4 months ago #160508
by Joshi
Replied by Joshi on topic how to add list of survey participants as possible answers for each question
It is still possible to type in any other name. I try to figure out how to validate the text input with the csv-list. The question validation tip could be something like this: „This person is not part of the course“
The topic has been locked.