- Posts: 58
- Thank you received: 9
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
- eloner
- Topic Author
- Offline
- Senior Member
Less
More
6 years 2 weeks ago #166605
by eloner
Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+ was created by eloner
Hello to everybody,
following the workaround manual.limesurvey.org/Workarounds:_Manip...r_LimeSurvey_2.05.2B and this post www.limesurvey.org/forum/development/114...r-using-autocomplete
I am trying to develop some LimeSurvey 2.06 examples using JQuery and the autocomplete function with the latest release of LimeSurvey (3.6.1+).
In the detail, I have created a survey with two questions:
- in the first, Q1, the list of names (Test1, Test2 and Test3) for autocompletion is included in the javascript code in the source of the question
- in the second, Q2, I use a csv file with a list of names (a list of italian cities).
Unfortunately, the first works well, but the second not.
I suppose something has changed from Lime 2.06 to 3.6... or perhaps I have made some error, or both.
In my attempt I have:
- extended the theme (fruity saved as fruity_copia);
- downloaded jQuery-UI;
- uploaded jquery-ui.min.css to /upload/themes/survey/fruity_copia/scripts/
- uploaded jquery-ui.min.css to /upload/themes/survey/fruity_copia/css/
- registered the two files in config.xml
- uninstalled the theme
- installed again the theme
- cleared the asset cache
- uploaded a csv file (provcode.csv) in the /upload/themes/survey/fruity_copia folder (only for Q2)
This worked well for Q1, but not for Q2.
I know that with lime 2.06 I have to edit the file startpage.pstpl , but I don't know if this is the case also for the new release of the program (in the theme fruity_copia there is not a file with this name).
I attach:
- the lss file of the survey
- the csv file
I think it is an interesting application of LimeSurvey, so... any help and suggestions are well accepted!
Cheers,
ELo
P.S. tested with Firefox 59.0.2 on Limesurvey 3.6.1+ on a server with Ubuntu 16.04.4, Apache 2.4.18, PHP 7.1.15, and mysql 14.14
following the workaround manual.limesurvey.org/Workarounds:_Manip...r_LimeSurvey_2.05.2B and this post www.limesurvey.org/forum/development/114...r-using-autocomplete
I am trying to develop some LimeSurvey 2.06 examples using JQuery and the autocomplete function with the latest release of LimeSurvey (3.6.1+).
In the detail, I have created a survey with two questions:
- in the first, Q1, the list of names (Test1, Test2 and Test3) for autocompletion is included in the javascript code in the source of the question
- in the second, Q2, I use a csv file with a list of names (a list of italian cities).
Unfortunately, the first works well, but the second not.
I suppose something has changed from Lime 2.06 to 3.6... or perhaps I have made some error, or both.
In my attempt I have:
- extended the theme (fruity saved as fruity_copia);
- downloaded jQuery-UI;
- uploaded jquery-ui.min.css to /upload/themes/survey/fruity_copia/scripts/
- uploaded jquery-ui.min.css to /upload/themes/survey/fruity_copia/css/
- registered the two files in config.xml
- uninstalled the theme
- installed again the theme
- cleared the asset cache
- uploaded a csv file (provcode.csv) in the /upload/themes/survey/fruity_copia folder (only for Q2)
This worked well for Q1, but not for Q2.
I know that with lime 2.06 I have to edit the file startpage.pstpl , but I don't know if this is the case also for the new release of the program (in the theme fruity_copia there is not a file with this name).
I attach:
- the lss file of the survey
- the csv file
I think it is an interesting application of LimeSurvey, so... any help and suggestions are well accepted!
Cheers,
ELo
P.S. tested with Firefox 59.0.2 on Limesurvey 3.6.1+ on a server with Ubuntu 16.04.4, Apache 2.4.18, PHP 7.1.15, and mysql 14.14
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
6 years 2 weeks ago #166648
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
Can you also attach an export of your template?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- eloner
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 58
- Thank you received: 9
6 years 2 weeks ago #166658
by eloner
Replied by eloner on topic Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
Here is a copy of the theme.
Kind regards,
Elo
Kind regards,
Elo
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
6 years 2 weeks ago #166736
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
I found a couple of problems:
1. You had some typos in config.xml.
2. The {TEMPLATEURL} placeholder no longer seems to work so I parsed the path another way.
So, this is now the script in the question source:
Here is a working version of your survey and a new copy of the theme.
1. You had some typos in config.xml.
2. The {TEMPLATEURL} placeholder no longer seems to work so I parsed the path another way.
So, this is now the script in the question source:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var qID = {QID}; var surveyRoot = location.pathname.split('index.php')[0]; var url = surveyRoot+"upload/themes/survey/fruity_copia_v2/provcode.csv"; // Create an array to hold the data var province= new Array(); // Grab the CSV contents $.get(url,function(data){ // Convert CSV contents to an array of arrays fullArray = $.csv.toArrays(data); // Load the data array $(fullArray).each(function(i, item){ province.push(item[0]); }); // Initialise the autocomplete plugin $('#question'+qID+' input[type="text"]').autocomplete({ source: province }); }); }); </script>
Here is a working version of your survey and a new copy of the theme.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: eloner
The topic has been locked.
- eloner
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 58
- Thank you received: 9
6 years 2 weeks ago #166770
by eloner
Replied by eloner on topic Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
Tested right now and works perfectly!
Thank you!
Cheers,
Eloner
Thank you!
Cheers,
Eloner
The topic has been locked.
- Elita
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 1
5 years 5 months ago #176887
by Elita
Replied by Elita on topic Javascript and autocomplete with / without a csv file on LimeSurvey 3.6.1+
Hello, tpartner, thank you for the solutions you provided. The question is - could, you, please, add the script that leaves empty field if there is no match entered? Thank you in advance -
Elita
Elita
The topic has been locked.