Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

relevance equation for short free text question

  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago #176659 by KompetenzZ
Hi,

I tried to set a relevance equation for a question group. The question group should only be displayed when:
Code:
Q00005 == "Groß-Enzersdorf" or "Zwettl-Niederösterreich"

Q00005 is a short free text question. Something is wrong, maybe the "==" is not working for text processing? Advices are welcome.


Maybe it seems strange that I would like to set relevance based on a short free text question. The reason is that I ask in Q00005 in which municipality the respondent live. I use the autocomplete function with a .csv file in Q00005 (see link).

manual.limesurvey.org/Workarounds:_Manip...r_LimeSurvey_2.05.2B

Based on this answer in which municipality the respondent live, a different question group should show up.
The only doubt I have is, if the relevance equation can store about 650 municipality names. Is there a character limit of the relevance equation text field? Or is there a more practical way to achieve this?

LimeSurvey Version: 3.14

Cheers kompetenzz
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176664 by holch
There is a good chance that the problems are the special characters "ß" and "ö". They are most probably saved differently in the database or you are running into trouble with utf-8.

I don't think the autocomplete question type is not the ideal for running relevance equations later.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176671 by Joffm
Hi,
without thinking about your other questions I should say the equation should be:
Q00005 == "Groß-Enzersdorf" or Q00005 =="Zwettl-Niederösterreich"


But you really should change your question to a tree question.
I think it's possible to ask first for a greater region like "Bundesland" then only the "Verwaltungsbezirke" of this.
Now you ask your autocomplete question with the csv of this "Verwaltungsbezirk".
I am sure you can do that by adding the results of the first two questions to the name of adapted csv files, like

municipality{Q1}{Q2}.csv


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago - 5 years 5 months ago #176677 by KompetenzZ
Replied by KompetenzZ on topic relevance equation for short free text question
Thank you very much. Such an obvious error: Write the question code after each "or" :blush:

Ok, I can ask first the "Bundesländer" and then the "Verwaltungsbezirk".
What do you mean with this:

I am sure you can do that by adding the results of the first two questions to the name of adapted csv files, like

municipality{Q1}{Q2}.csv


Do you mean instead of having one .csv-file for each "Bundesland", it is possible to have only one .csv-file which is somehow chained with a condition to autocomplete only the "Verwaltungsbezirke" of the "Bundesland" that was chosen before?

Cheers kompetenzz
Last edit: 5 years 5 months ago by KompetenzZ.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176689 by Joffm
After the respondent selected the "Verwaltungsbezirk" you only show the vities is this.
So you need an adapted csv file with only these options.

In the example JS code there is

var url = "templates/yourTemplate/countries.php";

So I thought to add a "&param={Q1}{Q2}"

var url = "templates/yourTemplate/countries.php&param={Q1}{Q2}";
in the php file you select this special csv
Code:
<?php
        $param=$_GET['param'];
 
  $countriesArr = array();
 
  $file_handle = fopen("myCSVfile".$param.".csv", "r");
....

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago - 5 years 5 months ago #176690 by KompetenzZ
Replied by KompetenzZ on topic relevance equation for short free text question
@holch
You are right. There is something going on with the special characters "ß" and "ö". I made a test survey to test the special characters (see attachment). Is there anything that I can do that that the relevance equation works for the special characters? Until now I saved the csv-file with UTF-8 (but if fact the .csv-file shouldn't matter). It is the relevance equation which makes troubles.

File Attachment:

File Name: limesurvey...4411.lss
File Size:16 KB

Cheers kompetenzz
Last edit: 5 years 5 months ago by KompetenzZ.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176702 by holch
The relevance equation makes trouble BECAUSE of the CSV, so yes, the CSV is of course involved in this. ;-)

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago - 5 years 5 months ago #176711 by KompetenzZ
Replied by KompetenzZ on topic relevance equation for short free text question
@holch: Look in the test survey, which I attached in my previous post (limesurvey...4411.lss). I made it without the autocomplete function (and therefore without a .csv) and the "ß" and "ö" in relevance equation still makes troubles (tested). The question group which should display doesn't show up.

@Joffm. Sorry it was not completely precise when I said I used the autocomplete feature from the manual. I also used explanations from the forum, otherwise it would not work with Version 3.14:
www.limesurvey.org/forum/can-i-do-this-w...esurvey-3-6-1#166770

I am sorry, I do not really understand your JS. I guess you used something from LS 2.x? Whereas I use 3.14. If you want to show me your approach, feel free to change the attached test survey (.lss) and theme (.zip) (in the theme is the autocomplete and the .csv-file).
If you want to do some adaption to the .csv-file with the states ("Bundesländer") and municipalities ("Gemeinden") I attached a separate .csv-file (gemeindenamen_liste_v2.csv) where the states and municipalities are included (the states are not included in the .csv-file which is currently placed in the theme).

File Attachment:

File Name: limesurvey...1-12.lss
File Size:21 KB

File Attachment:

File Name: extends1_b...1-12.zip
File Size:284 KB

File Attachment:

File Name: gemeindena...1-12.csv
File Size:56 KB

Cheers kompetenzz
Last edit: 5 years 5 months ago by KompetenzZ.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago - 5 years 5 months ago #176719 by Joffm
Well, in your code there is:

var url = surveyRoot+"upload/themes/survey/extends1_bootswatch/gemeindenamen_liste.csv";

So I said "Add a parameter like {Q1}{Q2}" you can do it like this

var url = surveyRoot+"upload/themes/survey/extends1_bootswatch/gemeindenamen_liste{Q1}{Q2}.csv";

You get smaller lists and maybe it's easier to handle and nobody can answer "Tirol" and "Eisenstadt"


And if I include the list directly as array there are no problems with German Umlauts.
Code:
$('#question'+qID+' input[type="text"]').autocomplete({
      minLength: 2, 
      source: [
"Eisenstadt",
"Rust",
"Breitenbrunn am Neusiedler See",
"Donnerskirchen",
"Großhöflein",
"Hornstein",
"Klingenbach",
"Leithaprodersdorf",
"Mörbisch am See",
"Müllendorf",
"Neufeld an der Leitha",
"Oggau am Neusiedler See",
"Oslip",
"Purbach am Neusiedler See",
....


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 5 months ago by Joffm.
The topic has been locked.
  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago #176727 by KompetenzZ
Replied by KompetenzZ on topic relevance equation for short free text question
I tried to do what you said:
I changed in the municipal question (Q2) the code:
Code:
var url = surveyRoot+"upload/themes/survey/extends1_bootswatch/gemeindenamen_liste{Q1}.csv";

It doesn’t work. Sample survey and theme is attached. So far I created .csv-files in the theme for the states "Burgenland" and "Kärnten". As far as I understand you I have to create one .csv-file for each state, isn't it?


Regarding umlauts: I mean the relevance equation in Group summary of question group g2 does not apply to g2 (see sample survey). The relevance equation is shown without an error but it is not applied for the words with umlauts within the relevance equation. This has nothing to with autocomplete and csv.

Cheers kompetenzz
The topic has been locked.
  • KompetenzZ
  • KompetenzZ's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 5 months ago - 5 years 5 months ago #176740 by KompetenzZ
Replied by KompetenzZ on topic relevance equation for short free text question
I am very sorry regarding the umlauts, everything is fine with them. I don't know why the relevance didn't work yesterday. Maybe there was an refresh/cache problem. Umlauts and ß work perfectly in relevance equations.


Now it is only the code in the municipal question which doesn't work. I just added the {Q1} (the state question) to the code (and inserted the two state-specific .csv-files to the theme directory):
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/extends1_bootswatch/gemeindenamen_liste{Q1}.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>

Is there something else to do as well? You wrote something about an .php-file in your previous post:
Code:
<?php
        $param=$_GET['param'];
 
  $countriesArr = array();
 
  $file_handle = fopen("myCSVfile".$param.".csv", "r");
....

If so, which .php-file do you mean? Or is this only for LS Version 2.x?

Cheers kompetenzz
Last edit: 5 years 5 months ago by KompetenzZ.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose