Validate answer in function of a previous answer

More
3 years 1 month ago #113601 by limes4LN
limes4LN created the topic: Validate answer in function of a previous answer
Hi,

I have Question 1 with 3 answers. Then, Question 2 where I want the user enter the lengh of his speech in this format M:SS (minutes:seconds).

1) What field I should use for Q2 ?
2) Do you have an example to valid the patten M:SS (I saw some example on the wiki, but regexp are not my friend)
3) if Answer from Q1 (A1) = foo, then, A2 must be less then 1:30, if A1 = bar, A2 must be less then 2:30, is it possible ?

Thanks

Please Log in to join the conversation.

More
3 years 1 month ago #113612 by tpartner
tpartner replied the topic: Validate answer in function of a previous answer
1) Short-text question type.

2) Some bigger brains than me may have more elegant expressions but this regex should work for less than 1:30:
/^(1:[0-2][0-9]|0:[0-5][0-9])$/
And this should work for less than 2:30:
/^(2:[0-2][0-9]|[0-1]:[0-5][0-9])$/

3) You can use the regexes in the "Question validation equation" with an IF statement. Something like this:
if(q1 == 'foo', regexMatch('/^(1:[0-2][0-9]|0:[0-5][0-9])$/', q1Regex), regexMatch('/^(2:[0-2][0-9]|[0-1]:[0-5][0-9])$/', q1Regex))
And perhaps a "Question validation tip" like this:
Must match format and be less than {if(q1 == 'foo', '1', '2')}:30


.

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

Please Log in to join the conversation.

More
3 years 1 month ago #113619 by limes4LN
limes4LN replied the topic: Validate answer in function of a previous answer
Hi tpartner,

Not sure I understood everything, but I will try this at home tonight, thanks !

Please Log in to join the conversation.

More
3 years 1 month ago #113621 by tpartner
tpartner replied the topic: Validate answer in function of a previous answer
Maybe this will help...

Sample survey:

File Attachment:

File Name: limesurvey...6895.lss
File Size:14 KB


With this logic in q2:



.

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

Please Log in to join the conversation.

More
3 years 1 month ago #113626 by limes4LN
limes4LN replied the topic: Validate answer in function of a previous answer
Well, thanks a lot, gonna try it ASAP : Thanks² !

Please Log in to join the conversation.

More
3 years 1 month ago #113819 by limes4LN
limes4LN replied the topic: Validate answer in function of a previous answer
Hello

I'm back and I have troubles to implement what I need exactly. My exemple was a tiny bit simpler then what I want to do

What my question validation equation should look :

if(
Q00021 == '1', regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032),
Q00023 == '1', regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032),
Q00024 == '1', regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032),
regexMatch('/^(1:00)$/', Q00032)
)

but it doesn't work.
I would like to do something like this :

if ( Q00021 == '1' OR Q00023 == '1' OR Q00024 == '1'); then
regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032
elif ( Q00022 == '2' OR Q00025 == '3' OR Q00026 == '2'); then
regexMatch('/^(2:[0-2][0-9]|3:[3][0])$/', Q00032
else
regexMatch('/^(0:[0-2][0-9])$/', Q00032
fi


How can I do that ?

Please Log in to join the conversation.

More
3 years 1 month ago #113830 by tpartner
tpartner replied the topic: Validate answer in function of a previous answer
Have a look at Expression Manager nested IF statements - manual.limesurvey.org/Expression_Manager#Equations_2

I think this is what you need (line breaks added for clarity):
if(Q00021 == '1' OR Q00023 == '1' OR Q00024 == '1', 
	regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032), 
	if(Q00022 == '2' OR Q00025 == '3' OR Q00026 == '2', 
		regexMatch('/^(2:[0-2][0-9]|3:[3][0])$/', Q00032), 
		regexMatch('/^(0:[0-2][0-9])$/', Q00032)
	)
)

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

Please Log in to join the conversation.

More
3 years 1 month ago #113831 by limes4LN
limes4LN replied the topic: Validate answer in function of a previous answer
Exactly what I need, I forgot about the "if" syntax, my fault, thanks a lot !

Please Log in to join the conversation.

More
3 years 1 month ago #113863 by limes4LN
limes4LN replied the topic: Validate answer in function of a previous answer
Tpartner, with your help, I did a big job, here it is :
if(Q00021 == '1' OR Q00023 == '1' OR Q00024 == '1', regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032),
  if(Q00021 == '3' OR Q00022 == '1' OR Q00023 == '3' OR Q00023 == '3' OR Q00023 == '5' OR Q00023 == '6' OR Q00024 == '2'  OR Q00025 == '1', regexMatch('/^(1:[3-5][0-9]|2:[0][0])$/', Q00032), 
    if(Q00021 == '4' OR Q00021 == '7' OR Q00021 == '9' OR Q00024 == '3' OR Q00024 == '4' OR Q00024 == '5', regexMatch('/^(1:[3-5][0-9]|2:[0-2][0-9]|2:[3][0])$/', Q00032), 
      if(Q00022 == '3' OR Q00022 == '4' OR Q00022 == '7' OR Q00025 == '2' OR Q00025 == '3' OR Q00025 == '4', regexMatch('/^(1:[3-5][0-9]|2:[0-5][0-9]|3:[0][0])$/', Q00032), 
		regexMatch('/^([0-9]:[0-5][0-9])$/', Q00032)
      )
    )
  )
)


But it doesn't work !
It only works if I do this for example
if(Q00021 == '1', regexMatch('/^(1:[0-2][0-9]|1:[3][0])$/', Q00032), regexMatch('/^([0-9]:[0-5][0-9])$/', Q00032)

I think I found a problem : Q00021, Q00022, Q00023 are not displayed at the same time, only one of them are displayed according to previous answers, the rest of them are hidden. Looks like this If statement is bogus when one of the question is the condition is hidden, it that possible?

Please Log in to join the conversation.

More
3 years 1 month ago #113875 by DenisChenu
DenisChenu replied the topic: Validate answer in function of a previous answer

limes4LN wrote: I think I found a problem : Q00021, Q00022, Q00023 are not displayed at the same time, only one of them are displayed according to previous answers, the rest of them are hidden. Looks like this If statement is bogus when one of the question is the condition is hidden, it that possible?

Use QCODE.NAOK :
This need to be clarified somewhere in our doc : manual.limesurvey.org/Expression_Manager#Syntax

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 to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!