Welcome to the LimeSurvey Community Forum

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

Validate answer in function of a previous answer

  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113601 by limes4LN
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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #113612 by tpartner
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:
Code:
/^(1:[0-2][0-9]|0:[0-5][0-9])$/
And this should work for less than 2:30:
Code:
/^(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:
Code:
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:
Code:
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.
The topic has been locked.
  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113619 by limes4LN
Hi tpartner,

Not sure I understood everything, but I will try this at home tonight, thanks !
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #113621 by tpartner
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.
The topic has been locked.
  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113626 by limes4LN
Well, thanks a lot, gonna try it ASAP : Thanks² !
The topic has been locked.
  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113819 by limes4LN
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 ?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #113830 by tpartner
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):
Code:
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.
The topic has been locked.
  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113831 by limes4LN
Exactly what I need, I forgot about the "if" syntax, my fault, thanks a lot !
The topic has been locked.
  • limes4LN
  • limes4LN's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113863 by limes4LN
Tpartner, with your help, I did a big job, here it is :
Code:
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
Code:
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?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #113875 by DenisChenu
Replied by DenisChenu on 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 , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose