- Posts: 25
- Thank you received: 0
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
- Topic Author
- Offline
- Junior Member
Less
More
9 years 6 months ago #113601
by limes4LN
Validate answer in function of a previous answer was created 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
9 years 6 months ago #113612
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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:
And this should work for less than 2:30:
3) You can use the regexes in the "Question validation equation" with an IF statement. Something like this:
And perhaps a "Question validation tip" like this:
.
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])$/
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))
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
9 years 6 months ago #113619
by limes4LN
Replied by limes4LN on 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 !
Not sure I understood everything, but I will try this at home tonight, thanks !
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
9 years 6 months ago #113621
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Validate answer in function of a previous answer
Maybe this will help...
Sample survey:
With this logic in q2:
.
Sample survey:
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:
The topic has been locked.
- limes4LN
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
9 years 6 months ago #113626
by limes4LN
Replied by limes4LN on topic Validate answer in function of a previous answer
Well, thanks a lot, gonna try it ASAP : Thanks² !
The topic has been locked.
- limes4LN
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
9 years 6 months ago #113819
by limes4LN
Replied by limes4LN on 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 :
How can I do that ?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
9 years 6 months ago #113830
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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):
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
9 years 6 months ago #113831
by limes4LN
Replied by limes4LN on topic Validate answer in function of a previous answer
Exactly what I need, I forgot about the "if" syntax, my fault, thanks a lot !
The topic has been locked.
- limes4LN
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
9 years 5 months ago #113863
by limes4LN
Replied by limes4LN on topic Validate answer in function of a previous answer
Tpartner, with your help, I did a big job, here it is :
But it doesn't work !
It only works if I do this for example
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?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13643
- Thank you received: 2491
9 years 5 months ago #113875
by DenisChenu
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.
Replied by DenisChenu on topic Validate answer in function of a previous answer
Use QCODE.NAOK :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?
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.