Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Autocomplete and automatically filled questions - csv

  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70785 by crescentio
Hello folks

I'm trying to design an autocomplete question, which is a numeric ID and the values come from a csv file placed in the template folder. When a value is choosen two another questions, that are hidden and in the same section, must be filled automatically. Here is an example of the csv:

123456,John,Doe
234567,Mary,Smith
3456789,Carl,Simpson

The two questions are "name" and "surname".
I'm trying to make this works with the help from this thread and his wiki post's son , but no success.
In the workarounds cited before, there is a link to the plugin but it doesn't works, so I found another source , but I'm not sure if this is the appropriate one.

I'm using the last release of LimeSurvey.
I hope that you can help me with this
Thanks in advance
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 3 months ago #70795 by tpartner

there is a link to the plugin but it doesn't works

Are you referring to the jquery.csv.js plugin? Doesn't work how?

Do you have the autocomplete portion of this workaround working?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70798 by crescentio
Hello Tony, thanks for answer.

Yes is the jquery.csv.js plugin. The site is in development, look .

No, the autocomplete from that workaround is not working.
Although, the automatically filled answers is more important to me than the autocomplete feature.

Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 3 months ago #70814 by tpartner
You need to get the autocompleting function to work first - the populating of following questions depends on that.

Are there any JavaScript errors? Can you activate a sample survey for us to see?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70826 by crescentio
Hello Tony, thanks

A sample survey is here .

The csv is equal to the example in the first post. The csv and the plugin are in templates/default folder.

The following code is in the source of the first question:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    var qID = 39255X1X1;             
    var qName = 39255X1X2;             
    var qSurname = 39255X1X3;
    var url = "templates/default/userdata.csv";
 
    // Create an array to hold the names
    var namesArr = new Array();
 
    // Grab the CSV contents
    $.get(url,function(data){
 
      // Convert CSV contents to an array of arrays
      fullArray = jQuery.csv()(data);
 
      // Load the names array
      $(fullArray).each(function(i, item){
        namesArr.push(item[0]);
      });
 
      // Initialise the autocomplete plugin
      $('#question'+qID+' input.text').autocomplete({
        source: namesArr,
        // Event fired when a selection is made (ui.item.value refers to the selected item)
        select: function(event, ui) { 
          // Find the "ID" and "Email" values associated with the selected name value and load those questions
          $(fullArray).each(function(i, item){
            if(item[0] == ui.item.value) {
              // The value from column 2 of the CSV
              $('#question'+qName+' input.text').val(item[1]);
              // The value from column 3 of the CSV
              $('#question'+qSurname+' input.text').val(item[2]);
            }
          }); 
        }
 
      });
    });
  });
</script>

I've attached the plugin too
jquery.csv.js
The topic has been locked.
  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70827 by crescentio
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 3 months ago - 12 years 3 months ago #70832 by tpartner
The question ID vars are not correct. You don't use the full SGQA, just the question ID .

This:
Code:
var qID = 39255X1X1;             
    var qName = 39255X1X2;             
    var qSurname = 39255X1X3;

Should be this:
Code:
var qID = 1;             
    var qName = 2;             
    var qSurname = 3;

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 12 years 3 months ago by tpartner.
The topic has been locked.
  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70834 by crescentio
Hi Tony, thanks

I did it in that way before and doesn't work. Anyway, I made the corrections in the sample survey and still autocomplete doesn't work.
Any other suggestion?

Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 3 months ago #70837 by tpartner
There is no link to the plugin. You need to follow all steps in the workaround:


- Download the jquery.csv.js plugin and place it in your template folder
- Add the following line to your startpage.pstpl BEFORE the tag for template.js
Code:
<script type="text/javascript" src="{TEMPLATEURL}jquery.csv.js"></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.
  • crescentio
  • crescentio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #70840 by crescentio
Thanks so much Tony

I feel so silly by forget that step :blush:
Although, when I was working in my localhost I did that step and the autocomplete doesn't work, maybe I forget another step.

Thanks so much, this was driving me crazy for days :laugh:
The topic has been locked.
More
11 years 1 month ago #91684 by Gabriela
Hi Tony, sorry, Im trying to achieve the same thing but with no results,
please can you check this? (as crescentio im working on localhost too)
Thanks a lot
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago #91699 by tpartner
Hi Gabriela,

Can you please explain what you are trying to do?

I see "Lingua", "provincia" and "Distrito" questions but I don't know how they are related. Do you want to auto-populate "provincia" and "Distrito" depending on "Lingua"?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose