Auto tick multiple choice answer based on a previous anwer

More
6 months 2 weeks ago #174785 by DenisChenu

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

Then
{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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: tpartner

Please Log in or Create an account to join the conversation.

More
2 months 1 week 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

Please Log in or Create an account to join the conversation.

More
2 months 1 week ago - 2 months 1 week 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
{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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last edit: 2 months 1 week ago by DenisChenu.

Please Log in or Create an account to join the conversation.

More
2 months 1 week ago - 2 months 1 week 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
Attachments:
Last edit: 2 months 1 week ago by develnick. Reason: clarification

Please Log in or Create an account to join the conversation.

More
2 months 1 week ago #180158 by DenisChenu
Oups for parenthesis:

Maybe try
{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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
2 months 1 week 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"
G1Q1_C=if(is_empty(isDone.NAOK), if(G2Q1_F == "Y", "Y", ""), G1Q1_C.NAOK)



question code: "isDone"
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

Please Log in or Create an account to join the conversation.

More
2 months 4 days ago #180466 by develnick
Hi Holch! I tried to use your code, but the answers doesn't bind each other.

- Nick

Please Log in or Create an account to join the conversation.

More
2 months 3 days 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
2 months 3 days 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:

<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:

<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.
Attachments:

Please Log in or Create an account to join the conversation.

More
2 months 3 days 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
2 months 2 days 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.
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

More
2 months 2 days ago - 2 months 2 days 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Attachments:
Last edit: 2 months 2 days ago by DenisChenu. Reason: PS

Please Log in or Create an account to join the conversation.

More
2 months 2 days ago #180566 by tpartner
Forward :
step1 (validation of current group) : 1st equation do Q1_SQ001= "" because Q1_SQ002 is empty

Yes, but that should (I think) happen on page load, not after I manually set Q1. I check the box so Q1_SQ001== "Y" and that should override the equation and let the second equation set Q2.

No?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
2 months 2 days ago #180572 by DenisChenu

tpartner wrote: Yes, but that should (I think) happen on page load, not after I manually set Q1. I check the box so Q1_SQ001== "Y" and that should override the equation and let the second equation set Q2.

No,

Equation is done on page load and at page validation (move next) , it's better like this (we have issue some year ago).

If you want not updated : i think you can use isDoneQ1 var to don't update current value.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 month 4 weeks ago #180631 by develnick
Thank you very much! It worked!

What happens if I have to bind a lot of questions, instad of copying and pasting the code for each question? Is there a way like that?

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


Example:

G1Q1
> A
> B
> C
...
Z

G2Q1
> A
> B
> C
...
> Z



Thanks!

- Nick

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!