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
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 11 months ago #166605 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

File Attachment:

File Name: limesurvey...8898.lss
File Size:15 KB

File Attachment:

File Name: provcode.csv
File Size:2 KB


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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 11 months ago #166648 by tpartner
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
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 11 months ago #166658 by eloner
Here is a copy of the theme.

File Attachment:

File Name: fruity_copia.zip
File Size:394 KB

Kind regards,
Elo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 11 months ago #166736 by tpartner
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:

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.

File Attachment:

File Name: limesurvey...4-04.lss
File Size:15 KB

File Attachment:

File Name: fruity_copia_v2.zip
File Size:366 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: eloner
The topic has been locked.
  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 11 months ago #166770 by eloner
Tested right now and works perfectly!
Thank you!
Cheers,
Eloner
The topic has been locked.
More
5 years 4 months ago #176887 by Elita
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
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose