The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

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

Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67518

  • Kent
  • Kent's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
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, This e-mail address is being protected from spambots. You need JavaScript enabled to view it

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 administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67520

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2869
  • Thank you received: 428
  • Karma: 246
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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67522

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2869
  • Thank you received: 428
  • Karma: 246
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.
<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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 1 year 7 months ago by tpartner.
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67523

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5116
  • Thank you received: 261
  • Karma: 240
Great solution, I think it's worth extending the "load data from CSV file" workaround!?

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67532

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2869
  • Thank you received: 428
  • Karma: 246
Sure Mazi, where is that?
Cheers,
Tony

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67541

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5116
  • Thank you received: 261
  • Karma: 240
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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67543

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2869
  • Thank you received: 428
  • Karma: 246
Yeah, I did but didn't realize that those were what you were reffering to. I'll do it.
Cheers,
Tony

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67545

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5116
  • Thank you received: 261
  • Karma: 240
Thanks ;-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 year 7 months ago #67546

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2869
  • Thank you received: 428
  • Karma: 246
Cheers,
Tony

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
  • Page:
  • 1
Moderators: DenisChenu, ITEd
Time to create page: 0.319 seconds
Donation Image