Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Just show one question from randomized group, hide the others

Just show one question from randomized group, hide the others 4 years 7 months ago #78759

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
Ah, ok here it is: Bugtracker.
Last Edit: 4 years 7 months ago by mr2jswe.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78778

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
Thanks, we'll look into it and might ask some further questions at the bug ticket.

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

Just show one question from randomized group, hide the others 4 years 7 months ago #78805

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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:
<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:
$('#questionQQ').hide();
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78824

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
TMSWhite wrote:
It isn't adequate to just call:
$('#questionQQ').hide();
Tom, that might lead to lots of problems because to my knowledge, lots of users are using
$('#questionQQ').hide();
...at their customized Javascript. Will all these calls not work properly?

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
Last Edit: 4 years 7 months ago by Mazi.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78826

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78922

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6574
  • Thank you received: 1477
  • Karma: 579
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?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78924

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78928

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6574
  • Thank you received: 1477
  • Karma: 579
Hmm, I don't see any $('#javaSGQA') element for text inputs.

Regardless, in my opinion, if a visible form element (text input, radio, checkbox, ...) is modified by JavaScript it should be detected on submit as it was in the past.

There may be many people running surveys with custom scripts expecting this behaviour.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 7 months ago #78949

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
Tony-

I just checked all of the question types. The name="SGQA" attribute is always associated with the visual input element (which is usually an id="answerSGQA" code). So, the example in this thread (which changes $('#answerSGQA')) WILL submit the value.

However, EM uses the hidden $('#javaSGQA') variable to process conditions. So, if people change an $('#answerSGQA') value but don't call checkconditions(), the downstream conditions processing won't happen.

So, people's JavaScript should continue to work as expected.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 2 years 9 months ago #105323

Awesome solutions!

Now I'm wondering: Let's say, I want to recycle my questions?

Let's say I want to use a pool of questions 2 times, in two different groups of questions (Q1, and Q2), I have the same ask# questions in each group.

I want to get different ones each time, I think I would have to check that the random generation of numbers, so I don't use the same number in my ask1, and ask2 questions in my poll. Up to them, I was find, but I've tried many times with the if function, but I can't get the work done :(

Can any one help me? :)

Thanks in advance
Last Edit: 2 years 9 months ago by javimontano. Reason: Did not explain my issue well :(
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 2 years 9 months ago #105341

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9600
  • Thank you received: 1376
  • Karma: 390
Hi,

No, if you want user see 2 question, you need 2 question in your survey.

Here you can have this:
- First question : Équation : {RAND(1,2)}
- Q1+Q1b : Relevance equation: RAND==1
- Q2+Q2b : Relevance equation: RAND==2

Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.391 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form