Autocomplete and automatically filled questions - csv

More
5 years 5 months ago #70785 by crescentio
crescentio created the topic: Autocomplete and automatically filled questions - csv
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

Please Log in to join the conversation.

More
5 years 5 months ago #70795 by tpartner
tpartner replied the topic: Autocomplete and automatically filled questions - csv

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.

Please Log in to join the conversation.

More
5 years 5 months ago #70798 by crescentio
crescentio replied the topic: Autocomplete and automatically filled questions - csv
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

Please Log in to join the conversation.

More
5 years 5 months ago #70814 by tpartner
tpartner replied the topic: Autocomplete and automatically filled questions - csv
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.

Please Log in to join the conversation.

More
5 years 5 months ago #70826 by crescentio
crescentio replied the topic: Autocomplete and automatically filled questions - csv
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:
<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

Please Log in to join the conversation.

More
5 years 5 months ago #70827 by crescentio
crescentio replied the topic: Autocomplete and automatically filled questions - csv
Oops
Here is the plugin:
dl.dropbox.com/u/1212092/jquery.csv.js

Please Log in to join the conversation.

More
5 years 5 months ago - 5 years 5 months ago #70832 by tpartner
tpartner replied the topic: Autocomplete and automatically filled questions - csv
The question ID vars are not correct. You don't use the full SGQA, just the question ID .

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

Should be this:
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: 5 years 5 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 5 months ago #70834 by crescentio
crescentio replied the topic: Autocomplete and automatically filled questions - csv
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

Please Log in to join the conversation.

More
5 years 5 months ago #70837 by tpartner
tpartner replied the topic: Autocomplete and automatically filled questions - csv
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
<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.
Attachments:

Please Log in to join the conversation.

More
5 years 5 months ago #70840 by crescentio
crescentio replied the topic: Autocomplete and automatically filled questions - csv
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:

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now