- Posts: 44
- Thank you received: 15
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Just show one question from randomized group, hide the others
- TMSWhite
- Offline
- LimeSurvey Community Team
Less
More
12 years 1 week ago #78698
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Replied by TMSWhite on topic Just show one question from randomized group, hide the others
Your question was that the initial solution didn't seem to be saving the data properly to the database. My best guess is that rand() is being called more than once (e.g. when data is finalized, or when wanting to print the answers), so the set of relevant questions changes and you end up with missing data.
The solution is to ensure that the randomization is only called once. The logic for Group0 looks like this:
Note that the if() function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
Here is the replacement survey (although I removed the final summary report - you can confirm you have the proper data by activating the survey and checking that the print answers screen shows the proper values).
The solution is to ensure that the randomization is only called once. The logic for Group0 looks like this:
Note that the if() function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
Here is the replacement survey (although I removed the final summary report - you can confirm you have the proper data by activating the survey and checking that the print answers screen shows the proper values).
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
- Expression Manager (EM):
Documentation
|
Sample Surveys
|
How Tos
|
Show Logic File
|
Upgrading to 1.92+ - Excel Style for Survey Structure Import/Export
Attachments:
The following user(s) said Thank You: mr2jswe
The topic has been locked.
- mr2jswe
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
12 years 1 week ago #78701
by mr2jswe
Replied by mr2jswe on topic Just show one question from randomized group, hide the others
Thank you, I have run your survey, reproduced it to my needs, and it works flawlessly all the way into the back-end database tables. Ive checked and double-checked.
It is now a coherent solution.
Again, thanks for your time and effort. I hope this will be of use to others as well. Cheers.
Johnny
It is now a coherent solution.
Again, thanks for your time and effort. I hope this will be of use to others as well. Cheers.
Johnny
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 1 week ago #78720
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Just show one question from randomized group, hide the others
Thanks for your solution and its documentation, Tom.
Johnny, please open a ticket at the bugtracker for the issues you noticed using my solution. It is weird that the result is not stored, this sounds like a bug.
Johnny, please open a ticket at the bugtracker for the issues you noticed using my solution. It is weird that the result is not stored, this sounds like a bug.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- mr2jswe
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
12 years 1 week ago #78722
by mr2jswe
Replied by mr2jswe on topic Just show one question from randomized group, hide the others
I have reported it to the Bugtracker just now. /J
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 1 week ago #78747
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Just show one question from randomized group, hide the others
Link?mr2jswe wrote: I have reported it to the Bugtracker just now. /J
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- mr2jswe
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
12 years 1 week ago - 12 years 1 week ago #78759
by mr2jswe
Replied by mr2jswe on topic Just show one question from randomized group, hide the others
Ah, ok here it is:
Bugtracker
.
Last edit: 12 years 1 week ago by mr2jswe.
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 1 week ago #78778
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Just show one question from randomized group, hide the others
Thanks, we'll look into it and might ask some further questions at the bug ticket.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- TMSWhite
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 44
- Thank you received: 15
12 years 1 week ago #78805
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Replied by TMSWhite on topic Just show one question from randomized group, hide the others
This isn't a bug in LS, but perhaps highlights a need to clarify how best to use custom JavaScript with Expression Manager.
Your custom JavaScript should have been:
Checkconditions() must be called in order for EM to process the new value you set for the variable (e.g. to ensure that the new value is stored within the hidden variables that are submitted, and call the relevance equations to change which questions are visible).
So, the documentation for this workaround needs to be updated for 1.92+. It isn't adequate to just call:
Your custom JavaScript should have been:
Code:
<script type="text/javascript"> <!-- $(document).ready(function() { // Find a random number between 1 and 4 var randNumber = Math.floor(Math.random()*3 + 1); $('input#answer12739X218X3728').val(randNumber); checkconditions(randNumber,'12739X218X3728','text'); }) //--> </script>
Checkconditions() must be called in order for EM to process the new value you set for the variable (e.g. to ensure that the new value is stored within the hidden variables that are submitted, and call the relevance equations to change which questions are visible).
So, the documentation for this workaround needs to be updated for 1.92+. It isn't adequate to just call:
Code:
$('#questionQQ').hide();
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
- Expression Manager (EM):
Documentation
|
Sample Surveys
|
How Tos
|
Show Logic File
|
Upgrading to 1.92+ - Excel Style for Survey Structure Import/Export
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 1 week ago - 12 years 1 week ago #78824
by Mazi
$('#questionQQ').hide();
...at their customized Javascript. Will all these calls not work properly?
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Just show one question from randomized group, hide the others
Tom, that might lead to lots of problems because to my knowledge, lots of users are usingTMSWhite wrote: It isn't adequate to just call:
Code:$('#questionQQ').hide();
$('#questionQQ').hide();
...at their customized Javascript. Will all these calls not work properly?
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Last edit: 12 years 1 week ago by Mazi.
The topic has been locked.
- TMSWhite
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 44
- Thank you received: 15
12 years 1 week ago #78826
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Replied by TMSWhite on topic Just show one question from randomized group, hide the others
Mazi-
Yes, that might be a problem for users, depending upon what they are trying to do.
EM processes conditions/relevance based upon new 'relevanceG'+$gid, 'relevance'+$qid, and 'relevance'+$sgqa values, rather than trying to infer whether a question is relevant from whether or not it is hidden.
There are plenty of cases where users want to hide values without making them irrelevant (e.g. if they are passing parameters in via the command line), so question visibility and relevance are distinct attributes.
If the user doesn't care whether data is collected from a hidden question, then calling $('#questionQQ').hide() is fine. However, hiding a variable via $('#questionQQ').hide() will not cause any cascading conditional logic to execute.
Of course, users could customize their template.js to add a jQuery.live() function to call checkconditions() whenever they issue a $('#questionQQ').hide() event, but that may be overkill, since EM-itself calls $('#questionQQ').hide() when a question is irrelevant, so I'm not sure what would happen if you tried to add a jQuery.live() event.
Perhaps Tony or Denis could propose simple ways to support users in this situation.
Yes, that might be a problem for users, depending upon what they are trying to do.
EM processes conditions/relevance based upon new 'relevanceG'+$gid, 'relevance'+$qid, and 'relevance'+$sgqa values, rather than trying to infer whether a question is relevant from whether or not it is hidden.
There are plenty of cases where users want to hide values without making them irrelevant (e.g. if they are passing parameters in via the command line), so question visibility and relevance are distinct attributes.
If the user doesn't care whether data is collected from a hidden question, then calling $('#questionQQ').hide() is fine. However, hiding a variable via $('#questionQQ').hide() will not cause any cascading conditional logic to execute.
Of course, users could customize their template.js to add a jQuery.live() function to call checkconditions() whenever they issue a $('#questionQQ').hide() event, but that may be overkill, since EM-itself calls $('#questionQQ').hide() when a question is irrelevant, so I'm not sure what would happen if you tried to add a jQuery.live() event.
Perhaps Tony or Denis could propose simple ways to support users in this situation.
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
- Expression Manager (EM):
Documentation
|
Sample Surveys
|
How Tos
|
Show Logic File
|
Upgrading to 1.92+ - Excel Style for Survey Structure Import/Export
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
12 years 1 week ago #78922
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 Just show one question from randomized group, hide the others
The firing of checkconditions() was always required for dynamic conditions on a page.
Tom, are you saying that if checkconditions() is not called, the value of an input field that was modified by JavaScript will not be detected when the form submits (the "Next" button is clicked) for use in conditions on subsequent pages?
Tom, are you saying that if checkconditions() is not called, the value of an input field that was modified by JavaScript will not be detected when the form submits (the "Next" button is clicked) for use in conditions on subsequent pages?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- TMSWhite
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 44
- Thank you received: 15
12 years 1 week ago #78924
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Replied by TMSWhite on topic Just show one question from randomized group, hide the others
As long as the proper javascript variable has its value set, the value will be submitted when the user clicks "next". In the example below, the user set the $('#answerSGQA") variable, which is the widget that lets the user see the value, but it is the $('#javaSGQA') variable that is typically the one submitted. checkconditions() not only triggers the conditional logic, but also tends to populate the $('#javaSGQA') variable if passed the value from the $('#answerSGQA') value.
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
- Expression Manager (EM):
Documentation
|
Sample Surveys
|
How Tos
|
Show Logic File
|
Upgrading to 1.92+ - Excel Style for Survey Structure Import/Export
The topic has been locked.