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

TOPIC: Answers filtered by previous question answers does not work

Answers filtered by previous question answers does not work 2 years 8 months ago #74038

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Hello to all the community,

I'm making a survey with answer options filtered by previous answers with this workaround. I have a test survey with previous workaround and works fine, but when I enter new answer options in that survey the workaround works very bad, erratic and missing answer options, or null answer options. Furthermore, if I rewrite the answer options from the previous functional survey, the workaround stops to work, null answer options.
This was made in the same questions of the same survey.

I'm using LimeSurvey Versión 1.91+ Build 12358
If you need more details just tell me.

Thanks in advance
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74244

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
Sorry, but we can't help when it comes to workarounds and even customized workarounds. This is way too complex and one would need to take a look at the complete code, survey set up and IDs which takes lots of time.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74283

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
A better and more portable way of handling this may be to use text inputs with the jQuery autocomplete workaround. The data source for the autocomplete list(s) could be defined depending on the previous answers.
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.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74866

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thanks for answer Marcel and Tony.

The jQuery autocomplete workaround could solve the problem, but how could I filter the answer options based on previous answers?
The options in the csv must be encoded as in the workaround I used?
The JavaScript code needs some change to work?

Thanks in advance, any help will be greatly appreciated
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74917

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
Mazi wrote:
Sorry, but we can't help when it comes to workarounds and even customized workarounds. This is way too complex and one would need to take a look at the complete code, survey set up and IDs which takes lots of time.
^- Sorry, but this really is a too complex issue...

User tpartner offers advanced, paid support and has great Javascript knowledge, so he should be able to help you out.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74930

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
OK thanks.
I'm not making too much money from this, it's more a learning process.

Another question is, what is the maximun number of items (rows) in a csv that can be handled with the autocomplete plugin?

Thanks in advance, and sorry if my issues are complex :(
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74947

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
...but how could I filter the answer options based on previous answers?
The easiest way would probably be to pass the result(s) of the previous questions (using {INSERTANS}) to the PHP file and have it select different CSV files or filter one - api.jquery.com/jQuery.getJSON/
...what is the maximun number of items (rows) in a csv that can be handled with the autocomplete plugin?
Dunno, but I have used it with 1000+ rows.
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: 2 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 8 months ago #74958

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
You can do what you need right now using LimeSurvey 1.92. There is a public demo of 1.92 that you can play with (www.limesurvey.org/demo) to test this out.

Since the filtering is really just 3 levels (Country, then City, then State), you can easily support that in LimeSurvey 1.92 like this:
(a) Ask country first (with list options B, C, and E)
(b) Have separate questions of states, by country, using the Country value as the relevance equation (e.g. country=='B' for Bolivia). Name them according to the country - e.g. the question titled Bstate will have the list BBE, BCH, and BCO.
(c) Have separate questions to select cities for each state, with state as the relevance criteria - so (Bstate == 'BBE') for Beni, would have a pick list of Loreto and Magdalena. Furthermore, call the question BBE so you know to which state it refers. Expression Manager will guarantee that the relevance logic will cascade, so you only need to ask whether the state matches - it will ensure that only states for the active country are considered.

(d) Finally, create Equation questions for state and city, and get the selected answer like this:

State:
list(Bstate,Cstate,Estate)

City:
list(BBE, BCO, CAT, CCU, CSA)

Since the list() function concatenates only non-null values, there will only be one value for state and city - the desired one. This gives you the code. If you want the display value, you would use:
list(BBE.shown, BCO.shown, CAT.shown, CCU.shown, CSA.shown)

Although this means splitting up your list into multiple questions, you would no longer be dependent upon a work-around.

Longer term, LimeSurvey could benefit from integration with an Enterprise Vocabulary Server (EVS), using the Clinical Terminology Services - 2 (CTS-2) specification API. That way you could do auto-complete into any large list, terminology, or even ontology. That is on the wish-list for Google Summer of Code, but is anyone else wants to give that a try, I can mentor on the details, since I'm already using CTS-2 compliant APIs for my day job.


/Tom
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 7 months ago #75425

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thanks so much Tony and Tom,
The easiest way would probably be to pass the result(s) of the previous questions (using {INSERTANS}) to the PHP file and have it select different CSV files or filter one - api.jquery.com/jQuery.getJSON/
I'm studying that posibility, it's a little bit difficult to me because I'm not a software programmer, but i'm learning.
Since the filtering is really just 3 levels (Country, then City, then State), you can easily support that in LimeSurvey 1.92 like this:
I will try your solution when other options are exhausted. If I understand, a question by state is not a reasonable option because I have 139 states. Although, I'll test your solution as a homework.

By the way, I'm testing the version 1.92 rc5 and the filter works at state level, but in the city level still doesn't work.
When I add the city options (550 options) and click on save this appears:
Access denied!

Security alert: Someone may be trying to use your LimeSurvey session (CSRF attack suspected). If you just clicked on a malicious link, please report this to your system administrator.
Also this problem can occur when you are working/editing in LimeSurvey in several browser windows/tabs at the same time.

When I reduce the amount of options to 200 it saves without errors, but the filter doesn't work.
I think the trouble in the workaround is the amount of options. I hope this issue will be resolved in the stable release or in another future release.

As a temporal alternative I'm trying to use this workaround, the csv method as appears there, but without success. Although, I think this is another thread issue.

Thanks so much
The administrator has disabled public write access.

Re: Answers filtered by previous question answers does not work 2 years 7 months ago #75564

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
I found a solution to the issue of erratic options. I don't know if this works with version 1.91, I did it in 1.92 rc5.

At Country level I used an option code of one character, as well as in State level, and two characters at City level:

Q1 Country
X country1

Q2 State
X state1

Q3 City
XX city1

In the State question I used the JavaScript code provided by tpartner:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Get the countryCode (first character of the country)
		var countryCode = '{INSERTANS:47126X993X12555}'.substr(0, 1).toUpperCase();
 
		// Loop through all dropdown options and remove those with codes not starting with the countryCode
		$('select[id^="answer"] option').each(function(i){
			if($(this).attr('value')  && $(this).attr('value').substr(0, 1).toUpperCase() != countryCode) {
				$(this).remove();
			}
		});
	});
</script>

And in the City question I modified the previous JavaScript code as:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Get the stateCode (two first characters of the state)
		var stateCode = '{INSERTANS:47126X993X12555}'.substr(0, 2).toUpperCase();
 
		// Loop through all dropdown options and remove those with codes not starting with the stateCode
		$('select[id^="answer"] option').each(function(i){
			if($(this).attr('value')  && $(this).attr('value').substr(0, 2).toUpperCase() != stateCode) {
				$(this).remove();
			}
		});
	});
</script>

Now the workaround works fine with 550 options (cities).

The Access denied! error when adding a relatively large amount of options, seems to be due to Suhosin, as I read somewhere.

Thanks to tpartner, TMSWhite, and Mazi for your help.
Last Edit: 2 years 7 months ago by crescentio.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.301 seconds
Donation Image