Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: 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 2 Jahre 9 Monate her #67518

  • Kent
  • Kents Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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, Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!

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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67520

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4050
  • Dank erhalten: 740
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67522

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4050
  • Dank erhalten: 740
  • Karma: 341
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 Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Letzte Änderung: 2 Jahre 9 Monate her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67523

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5300
  • Dank erhalten: 291
  • Karma: 247
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'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67532

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4050
  • Dank erhalten: 740
  • Karma: 341
Sure Mazi, where is that?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67541

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5300
  • Dank erhalten: 291
  • Karma: 247
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'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67543

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4050
  • Dank erhalten: 740
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67545

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5300
  • Dank erhalten: 291
  • Karma: 247
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'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 2 Jahre 9 Monate her #67546

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4050
  • Dank erhalten: 740
  • Karma: 341
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Autocomplete a question from csv and fill two more question from same CSV 1 Jahr 1 Monat her #97054

  • xsiyez
  • xsiyezs Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 18
  • Karma: 0
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
Anhang:
Letzte Änderung: 1 Jahr 1 Monat her von xsiyez.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.175 Sekunden
Donation Image