Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Autocomplete and automatically filled questions - csv

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70785

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70795

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70798

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70814

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70826

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70827

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Oops
Here is the plugin:
dl.dropbox.com/u/1212092/jquery.csv.js
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70832

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
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: 4 years 4 months ago by tpartner.
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70834

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70837

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
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>
Attachments:
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 4 years 4 months ago #70840

  • crescentio
  • crescentio's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 3 years 3 months ago #91684

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • Karma: 0
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
Attachments:
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 3 years 3 months ago #91699

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
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 administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 3 years 3 months ago #91704

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
For this workaround to work, you need to:
1) Include the CSV file in your template directory
2) Place the jquery.csv.js file in your template directory
3) Add the following line to your startpage.pstpl AFTER the {TEMPLATEJS} tag
<script type="text/javascript" src="{TEMPLATEURL}jquery.csv.js"></script>

Your code looked fine to me but I modified it a bit to automatically detect the question IDs and the the path to the template directory.

Placing this code in the source of the first question will initiate the auto-complete function for that question, using the CSV column-1 values. When a value is selected, it will auto-populate the following 2 questions with the the CSV column-2 and column-3 values.

For different questions/surveys, all you should need to modify is the csvName variable.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Define the CSV filename
		var csvName = 'linguas.csv';
 
		// Define some paths
		var surveyRoot = location.pathname.split('index.php')[0];
		var templateName = $('head link[href*="template.css"]').attr('href').replace(/\/template.css/, '').split('/templates/')[1];
		var templatePath = surveyRoot+'upload/templates/'+templateName+'/';
 
		// Define the questions
		var q1ID = '{QID}';	
		var q1 = $('#question'+q1ID);
		var q2 = $(q1).nextAll('.text-short:eq(0)');
		var q3 = $(q1).nextAll('.text-short:eq(1)');
 
		// Define the path to the CSV
		var url = templatePath+csvName;
 
		// Create an array to hold the CSV rows
		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 CSV rows array
			$(fullArray).each(function(i, item){
				namesArr.push(item[0]);
			});
 
			// Initialise the autocomplete plugin
			$('input.text', q1).autocomplete({
				source: namesArr,
				// Event fired when a selection is made (ui.item.value refers to the selected item)
				select: function(event, ui) { 
					// Find the column 2 and column 3 values associated with the selected column 1 value and load q2 and q3
					$(fullArray).each(function(i, item){
						if(item[0] == ui.item.value) {
							// The value from column 2 of the CSV
							$('input.text', q2).val(item[1]);
							// The value from column 3 of the CSV
							$('input.text', q3).val(item[2]);
						}
					}); 
				}
 
			});
		});
	});
</script>

Here is a working copy of your survey and the corresponding template with the CSV file and jquery.csv.js included. (import the template first so the survey uses the correct one)

File Attachment:

File Name: gabriela_csv_test.zip
File Size:74 KB


File Attachment:

File Name: autofillcvs_TP.lss
File Size:28 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 3 months ago by tpartner.
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 3 years 3 months ago #91719

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • Karma: 0
Merci!!! I was all day in this and no moving...(mega frustrating..)
I still didt try it, but reading I can see the first difference. I was following the previuos answers where you said:

- 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

Before. :dry:
But its After?
super.

ok, now Ill try..

It works!! but only with "gabriela csv test" template. Have to check differences with mine.

Have to go to work now, but as soon as I can ill find out what is going wrong..

Thank you so much, it made my day.

ps: In "gabriela csv test" template, startpage, appears in one corner TEMPLATEJS sorrounded by red square, type of , "variable undefined". (but still working, strange)
The administrator has disabled public write access.

Autocomplete and automatically filled questions - csv 3 years 3 months ago #91734

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5780
  • Thank you received: 1258
  • Karma: 514
I was following the previuos answers where you said...Add the following line to your startpage.pstpl BEFORE the tag for template.js
Those instructions are for LimeSurvey 1.92. Things are slightly different in LimeSurvey 2.0.
In "gabriela csv test" template, startpage, appears in one corner TEMPLATEJS sorrounded by red square...
Can you provide a screenshot?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.253 seconds