Welcome to the LimeSurvey Community Forum

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

Auto tick multiple choice answer based on a previous anwer

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #174785 by DenisChenu

develnick wrote: Ok. And what happens if the user hits the "Previous" button? Is this code executed?

Then
Code:
{q1_c=if(is_empty(q1_c.NAOK,if(q2_f=="Y", "Y",""),q1_c.NAOK)}
Then if q1_c are set by user, this didn't update it.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: tpartner
The topic has been locked.
  • develnick
  • develnick's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 2 months ago #180128 by develnick
Hi Denis, I tried to use your code but it didn't work. Is there a method to bind the answers?

The "previous" button is always ON, so the user can always change the answer.

And also, if I use at the same time

{q2_f=if(q1_c=="Y", "Y","")} for question q2_f

{q1_c=if(q2_f=="Y", "Y","")} for question q1_c

the link didn't work

- Nick
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago - 5 years 2 months ago #180151 by DenisChenu
With checkbox : uncjecked checkbox is empty.

Maybe better with
Create 2 equation question
First one : your equation : {q1_c=if(is_empty(isDone.NAOK),if(q2_f=="Y", "Y",""),q1_c.NAOK)}{q1_b=if(is_empty(isDone.NAOK),if(q2_g=="Y", "Y",""),q1_c.NAOK)}
Second one named isDone : equation 1

Else about : «it didn't work» : and ? Yes ? It diodn't work for you … but you don't give any information . For example a screenshot of the survey logic file ?

EDIT
Code:
{q2_f=if(q1_c=="Y", "Y","")}
{q1_c=if(q2_f=="Y", "Y","")}
? What is this eqaution ??? q2_f are updated by q1_c and was updated by q2_f
I think in this condition : the equation are get in order.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 2 months ago by DenisChenu.
The topic has been locked.
  • develnick
  • develnick's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 2 months ago - 5 years 2 months ago #180157 by develnick
Hi Denis thank you for your reply!

Let me clarify the behavior I would replicate.

I have this survey - you can see in the attachment - that makes it possible to go back and change the previous question, so the "back" and the menu button are enabled.

G1 is the first question group and contains a list of questions S
G2 is the second question group and contains a subset of S

G1 has two questions:
  • G1Q1 (multiple-choice; )
  • g1_autotick (equation; the code to to bind G1Q1 and G2Q1 )

- G1Q1 has three answers
  • Document A
  • Document B
  • Document C

G2 has two questions:
  • g2_autotick (equation; the code to bind G2Q1 and G1Q1)
  • G2Q1 (multiple-choice)


- G2Q1 has three answers:
  • Document D
  • Document E
  • Document C


Expected Behavior

Standard example:

If the User selects Document C from G1Q1, he will see Document C auto-selected in G2Q1.
If the User selects Document C from G2Q1, he will see Document C auto-selected in G1Q1, after hitting the previous button.

Another example:

If the User selects Document C from G1Q1 and de-selects document C from G2Q1, he will see Document C de-selected from G1Q1, after hitting the previous button.

If the User doesn't select Document C from G1Q1 and and selects Document C from G2Q1, he will see Document C auto-selected from G1Q1, after hitting the previous button.


Problems

I tried to use your code but it says "Missing close parenthesis"



Then I tried to re-factor the parenthesis, but it says "Function does not support too many arguments"



Then I re-interpreted your code and:



Then I tried to test the survey another time but:

See the video


The code from works however only one-way:

Document C of G1Q1---> Document C of G2Q1 (bind OK)
Document C of G1Q1 <--- Document C of G2Q1 (bind FAIL)

Document C of G1Q1 ---> Document C of G2Q1 (bind FAIL)
Document C of G1Q1 <--- Document C of G2Q1 (bind ok)

- Nick
Last edit: 5 years 2 months ago by develnick. Reason: clarification
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #180158 by DenisChenu
Oups for parenthesis:

Maybe try
Code:
{q1_c=if(is_empty(isDone.NAOK),if(q2_f=="Y", "Y",""),q1_c.NAOK)}{q1_b=if(is_empty(isDone.NAOK),if(q2_g=="Y", "Y",""),q1_c.NAOK)}
With the equation question type.

No time currently to look at your survey.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • develnick
  • develnick's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 2 months ago #180168 by develnick
Hi Denis, don't worry about the parenthesis.

I don't understand where to put your code (I changed your variables with the survey's ones)

question code: "question1"
Code:
G1Q1_C=if(is_empty(isDone.NAOK), if(G2Q1_F == "Y", "Y", ""), G1Q1_C.NAOK)



question code: "isDone"
Code:
G2Q1_F=if(is_empty(isDone.NAOK), if(G1Q1_C == "Y", "Y", ""), G2Q1_F.NAOK)




I tried that but it works only one-way.

- Nick
The topic has been locked.
  • develnick
  • develnick's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 2 months ago #180466 by develnick
Hi Holch! I tried to use your code, but the answers doesn't bind each other.

- Nick
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #180506 by DenisChenu

develnick wrote: I tried that but it works only one-way.

Yes,

I understand : but i don't understand what is your exact need …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #180510 by tpartner
It seems that the two equations are fighting each other. I could not get it to work, even using simple equations that did not check for previous answers. If you use an equation to conditionally set Q1, you cannot use the value of Q1 in another conditional setting equation on the next page. It seems to return null.

(this might be seen as a bug)

As a workaround - JavaScript! :)

Place a script like this in the source of the first question:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    var checkedState = false;
    if('{G2Q1_F}' == 'Y') {
      checkedState = true;
    }
    $('#answer{SGQ}C').prop('checked', checkedState).trigger('change');
  });
</script>

And then something like this in the source of the second question:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    var checkedState = false;
    if('{G1Q1_C}' == 'Y') {
      checkedState = true;
    }
    $('#answer{SGQ}F').prop('checked', checkedState).trigger('change');
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3154.lss
File Size:23 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #180527 by DenisChenu

tpartner wrote: It seems that the two equations are fighting each other. I could not get it to work, even using simple equations that did not check for previous answers. If you use an equation to conditionally set Q1, you cannot use the value of Q1 in another conditional setting equation on the next page. It seems to return null.

(this might be seen as a bug)

I'm unsure ;) , but i need a complet lss showing exact issue.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #180560 by tpartner

I'm unsure ;) , but i need a complet lss showing exact issue.


Here is a basic survey. The question value assignment does not work going forwards but does work going backwards.



Survey attached:

File Attachment:

File Name: limesurvey...2-15.lss
File Size:24 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: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago - 5 years 2 months ago #180561 by DenisChenu
Forward :
step1 (validation of current group) : 1st equation do Q1_SQ001= "" because Q1_SQ002 is empty
step2 (validation of next group) : 2nd equation do Q1_SQ002= "" because Q1_SQ001 is empty

Backward:
2nd equation didn't happen (we don't validate current group)
step2 (validation of previous group) : 1st equation do Q1_SQ001=Q1_SQ002 because Q1_SQ002 is empty *

I really think it's not an issue :)
And clearly :
step1 from forward happen

Possible solution : use more group ?

PS : i think usage of isDoneQ1 and isDoneQ2 can do the trick too.
PS2 : see wityh doneQ2 : partial fix. The issue is more «What is the condition to update (or not) Q1»

File Attachment:

File Name: limesurvey...Done.lss
File Size:25 KB

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 2 months ago by DenisChenu. Reason: PS
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose