how to add list of survey participants as possible answers for each question

More
1 month 1 week ago #160249 by digitaldust
digitaldust created the topic: how to add list of survey participants as possible answers for each question
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.

Please Log in to join the conversation.

More
1 month 1 week ago #160250 by Joffm
Joffm replied the topic: how to add list of survey participants as possible answers for each question
Thre is a workaround in the manual:
https://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Use_jQuery_Autocomplete_plugin_to_suggest_answers_for_text_inputs

with several options.

I suppose there are not too much names, so the first option should be fine.




Regards
Joffm
Attachments:
The following user(s) said Thank You: digitaldust

Please Log in to join the conversation.

More
1 month 1 week ago #160252 by digitaldust
digitaldust replied the 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!

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #160254 by Joffm
Joffm replied the 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:
<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:
<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
Last Edit: 1 month 1 week ago by Joffm.
The following user(s) said Thank You: Joshi

Please Log in to join the conversation.

More
1 month 1 week ago #160257 by digitaldust
digitaldust replied the 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...

Please Log in to join the conversation.

More
1 month 1 week ago #160258 by digitaldust
digitaldust replied the 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

Please Log in to join the conversation.

More
1 month 1 week ago #160259 by tpartner
tpartner replied the 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:

<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:

File Attachment:

File Name: limesurvey...1-02.lss
File Size:13 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
1 month 1 week ago #160263 by digitaldust
digitaldust replied the 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.

Please Log in to join the conversation.

More
1 month 1 week ago #160266 by Joffm
Joffm replied the 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.

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).

In my array there are about 80 different names.

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

Please Log in to join the conversation.

More
1 month 1 week ago #160267 by digitaldust
digitaldust replied the 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.

Please Log in to join the conversation.

More
1 month 1 week ago #160268 by tpartner
tpartner replied the 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:
<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:
unique(self)

4) Give the question a validation tip something like this:
{if(unique(self), '', 'Answers must be unique!')}

Sample survey attached:

File Attachment:

File Name: limesurvey...02-2.lss
File Size:16 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: Joshi, digitaldust

Please Log in to join the conversation.

More
1 month 5 hours ago #160508 by Joshi
Joshi replied the 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“

Please Log in to join the conversation.

More
4 weeks 1 day ago #160518 by DenisChenu
DenisChenu replied the topic: how to add list of survey participants as possible answers for each question
No manual, no free help, 2.7X tested, need 2 questions :
1. One long text question to have the list of answer
2. One hidden single choice question for answers labels (and code)
javascript only solution

Plugin : framagit.org/SondagePro-LimeSurvey-plugin/selectQuestionBy
Plugin dependance : framagit.org/SondagePro-LimeSurvey-plugin/select2package

Denis

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).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!