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
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160249 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.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160250 by Joffm
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

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: digitaldust
The topic has been locked.
  • digitaldust
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160252 by digitaldust
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!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago - 6 years 4 months ago #160254 by Joffm
In the manual it's explained step by step.
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
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160257 by digitaldust
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...
The topic has been locked.
  • digitaldust
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160258 by digitaldust
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
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160259 by tpartner
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:

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:

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.
The topic has been locked.
  • digitaldust
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160263 by digitaldust
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
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160266 by Joffm
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

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • digitaldust
  • digitaldust's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 4 months ago #160267 by digitaldust
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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160268 by tpartner
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:
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:

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.
The following user(s) said Thank You: Joshi, digitaldust
The topic has been locked.
More
6 years 4 months ago #160508 by Joshi
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.

Lime-years ahead

Online-surveys for every purse and purpose