Welcome to the LimeSurvey Community Forum

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

Autocomplete a question from csv and fill two more question from same CSV

More
12 years 5 months ago #67518 by Kent
Hi,

Has anyone done this or knows how it could be done with Limesurvey.

In my survey I want the user to choose to enter a name that is autocompleted for accuracy.

My CSV is like this

Name,ID#,email
Bob, 123, bob@somehwere.com

1st question would be to enter name - so you start typing and it autocompletes and you choose Bob. I then would like it to automatically fill the next two question which are ID # and email - (from that CSV).

Is there some sort of hack that someone has tried to do this - I'm still trying to get the autocomplete workaround to work ;) Thanks in advance for any advice.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 5 months ago #67520 by tpartner
I think you may need to do it in two steps:

1) Use the autocomplete workaround to fill the name field.

2) Use a plugin like js-tables to convert the CSV to an array of arrays. When a change to the name field is detected you could loop through this array to get the ID and email values.

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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 5 months ago - 12 years 5 months ago #67522 by tpartner
Hmm, after a little exploring, it turns out that there is a "select" event that gets fired when an autocomplete selection is made. This means that you don't need the listener. You can use that event to populate your ID and Email questions.

So, assuming all questions are on the same page, the script would look something like The following.

Replace:
- "NN" with the "Name" question ID
- "II" with the "ID" question ID
- "EE" with the "Email" question ID

Modify the path to your CSV file.
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    var qNameID = NN;             
    var qIDID = II;             
    var qEmailID = EE;
    var url = "upload/templates/yourTemplate/yourCsvFile.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'+qNameID+' 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) {
              $('#question'+qIDID+' input.text').val(item[1]);
              $('#question'+qEmailID+' input.text').val(item[2]);
            }
          }); 
        }
 
      });
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 12 years 5 months ago by tpartner.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
12 years 5 months ago #67523 by Mazi
Great solution, I think it's worth extending the "load data from CSV file" workaround!?

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 5 months ago #67532 by tpartner
Sure Mazi, where is that?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
12 years 5 months ago #67541 by Mazi
I think there are two autocomplete workarounds, one deals with loading data from CSV files.
Didn't you add those?

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 5 months ago #67543 by tpartner
Yeah, I did but didn't realize that those were what you were reffering to. I'll do it.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
12 years 5 months ago #67545 by Mazi
Thanks ;-)

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 5 months ago #67546 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 9 months ago - 10 years 9 months ago #97054 by xsiyez
Hi Tony

I do not seem to get this work on my side. I have followed all the steps from this post and the workaround here ,downloaded the jquery.csv.js plugin added it to my template created 2 questions in the same group and modified the javascript provided on the workaround to suite my environment.

When I launch the question group I do not get any autocompeltion and firebug gives the following errors in the console:

1. ReferenceError: jQuery is not defined
[Break On This Error]
})(jQuery);
jquery.csv.js (line 191)

2. TypeError: jQuery.csv is not a function
fullArray = jQuery.csv()(data);

I can confirm that jquery.csv.js gets loaded as I can see it in the html source code and in firebug. Please find attached the javascript file I modified from the workaround mentioned above and after following this post togehter with my sample CSV file. Any assistance will be greatly appreciated.

Alex
Last edit: 10 years 9 months ago by xsiyez.
The topic has been locked.
More
10 years 9 months ago #97056 by xsiyez
Hi

I managed to resolve the first one because I loaded jquery.csv.js before jquery. However, am still not able to this work.
Code:
TypeError: jQuery.csv is not a function
fullArray = jQuery.csv()(data);

Still persists in Firebug. Please help.
The topic has been locked.
More
10 years 9 months ago #97101 by xsiyez
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose