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

TOPIC: Autocomplete not working

Autocomplete not working 5 months 3 weeks ago #101191

  • amazon3d
  • amazon3d's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
I have been trying all day to get autocomplete to work with Lime Survey.
I tired something basic like states, cities, zip codes. I could not get any of them to work. I followed the instructions at Workarounds but was not able to get it working. Can someone point me to a more elaborate explanation of this guide? What am I supposed to replace QQ with? The question code, Input ID, Input Name? I've tried all 3 and autocomplete didn't fire off when I started typing. Example at remote.graycomputer.net/ (autocomplete test). Hosting it locally for testing.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101213

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
QQ should be replaced by the question ID:
he322708.PNG


So, in your test survey:
var q1ID = 114;
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.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101215

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Or simpler, try this:
var q1ID = {QID};
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.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101220

  • amazon3d
  • amazon3d's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
THANK YOU!!!!!!!!

I worked on this all day yesterday.
Second question is if you have multiple short answers how do you get this to work for something like an address (City, State, Zip) that have different lookups?
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101221

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Something like this should work:

<script charset="utf-8" type="text/javascript">
 
        $(document).ready(function() {
 
                var q1ID = {QID};
 
                var cities = "Greenville,Franklin,Clinton,Springfield,Bristol,Salem,Fairview,Washington,Madison,Georgetown,Arlington,Marion,Oxford".split(',');
 
                var states = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware, District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky, Louisiana,Maine,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York, North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Maryland,Massachusetts,Michigan, Minnesota,Mississippi,Missouri,Pennsylvania,Rhode Island,South Carolina,South Dakota, Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming".split(',');
 
                var zips = "11111,22222,33333,44444,55555,66666,77777,88888,99999".split(',');
 
                $('#question'+q1ID+' input.text:eq(0)').autocomplete({
                        source: cities
                });
                $('#question'+q1ID+' input.text:eq(1)').autocomplete({
                        source: states
                });
                $('#question'+q1ID+' input.text:eq(2)').autocomplete({
                        source: zips
                });
 
        });
 
</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.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101222

  • amazon3d
  • amazon3d's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
input.text:eq(0)

Is this a built in feature so LS knows which part of the array your answering?
And will this also work with an array?
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101223

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
That is a jQuery selector that finds the first input with a class of "text" - api.jquery.com/eq/

For arrays or other question types you may need to modify the selector. Use a tool like Firebug for Firefox to explore the DOM.
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.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101228

  • amazon3d
  • amazon3d's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
I tried modifying the code to use CSV files but it seems to hang Zip codes on the Cities and then breaks from there.
Did I do something wrong here?
Or did I go down the totally wrong path for CSV?
        $(document).ready(function() {
 
        var q1ID = {QID};
        var cities = "http://localhost/templates/default/cities.php";
	var dataArr = [];
	$.getJSON(url,function(data){
 
                        $.each(data,function(i, item){
                                dataArr.push(item);
                        });
 
                        $('#question'+q2ID+' input.text:eq(1)').autocomplete({
                                source: dataArr
                        });
 
                });
 
        });
 
        $(document).ready(function() {
 
                var q2ID = {QID};		
                var states = "http://localhost/templates/default/states.php";
		var dataArr = [];
		$.getJSON(url,function(data){
 
                        $.each(data,function(i, item){
                                dataArr.push(item);
                        });
 
                        $('#question'+q2ID+' input.text:eq(1)').autocomplete({
                                source: dataArr
                        });
 
                });
 
        });
 
        $(document).ready(function() {
 
                var q3ID = {QID};
                var url = "http://localhost/templates/default/zipcodes.php";
		var dataArr = [];
		$.getJSON(url,function(data){
 
                        $.each(data,function(i, item){
                                dataArr.push(item);
                        });
 
                        $('#question'+q3ID+' input.text:eq(2)').autocomplete({
                                source: dataArr
                        });
 
                });
 
        });
Last Edit: 5 months 3 weeks ago by amazon3d.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101232

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Here's how I would have handled that:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		var qID = {QID};
 
		var citiesURL = "http://localhost/templates/default/cities.php";
		var citiesArr = [];
		$.getJSON(citiesURL, function(data){
 
			$.each(data,function(i, item){
				citiesArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(0)').autocomplete({
				source: citiesArr
			});
		});
 
		var statesURL = "http://localhost/templates/default/states.php";
		var statesArr = [];
		$.getJSON(statesURL, function(data){
 
			$.each(data,function(i, item){
				statesArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(1)').autocomplete({
				source: statesArr
			});
		});
 
		var zipURL = "http://localhost/templates/default/zipcodes.php";
		var zipArr = [];
		$.getJSON(zipURL, function(data){
 
			$.each(data,function(i, item){
				zipArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(2)').autocomplete({
				source: zipArr
			});
		});
 
	});
</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.
Last Edit: 5 months 3 weeks ago by tpartner.
The administrator has disabled public write access.

Autocomplete not working 5 months 3 weeks ago #101233

  • amazon3d
  • amazon3d's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 16
  • Karma: 0
Tried that iteration of the code and was not able to have success with it. I thank you for your time and patience Tony. I've attached all the code for the various parts of the script.
I'm going to continue trying to find my break point but if you see something obvious let me know.


I was able to get Zip and City working but State is not firing, I checked the code in all 3 sections (CSV PHP and JS) and it appears to be identical aside from the variable names.

Question Source:
What is your address? 
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		var qID = {QID};
 
    	var citiesURL = "http://localhost/templates/default/cities.php";
		var citiesArr = [];
		$.getJSON(citiesURL, function(data){
 
			$.each(data,function(i, item){
				citiesArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(0)').autocomplete({
				source: citiesArr
			});
		});
 
    	var statesURL = "http://localhost/templates/default/states.php";
		var statesArr = [];
		$.getJSON(statesURL, function(data){
 
			$.each(data,function(i, item){
				statesArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(1)').autocomplete({
				source: statesArr
			});
		});
 
    	var zipURL = "http://localhost/templates/default/zipcodes.php";
		var zipArr = [];
		$.getJSON(zipURL, function(data){
 
			$.each(data,function(i, item){
				zipArr.push(item);
			});
 
			$('#question'+qID+' input.text:eq(2)').autocomplete({
				source: zipArr
			});
		});
 
	});
</script>

cities.php source
<?php
 
        $citiesArr = array();
 
        $file_handle = fopen("http://localhost/templates/default/cities.csv", "r");
 
        while (!feof($file_handle) ) {
                $line_of_text = fgetcsv($file_handle);
                array_push($citiesArr, $line_of_text[0]);
        }
 
        fclose($file_handle);
 
        echo json_encode($citiesArr);
 
?>
cities.csv source
Douglas
Broxton
Pearson
Hazlehurst
West Green
Ambrose
Atlanta
Orlando
Last Edit: 5 months 3 weeks ago by amazon3d.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.229 seconds
Donation Image