- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Problem with validation equation with 2 dropdown values
- testls2018
- Topic Author
- Offline
- New Member
I am new to LimeSurvey (3.15) and I need your help.
The problem is : I have two dropdown lists with values [0,5,10,...,100] and it appears that some values are not correct in the condition.
On the 1st dropdown (q9), i only choose a value from the list.
On the 2nd dropdown (q911), i have added on Question validation equation (! is_empty(q911.shown) and q911.shown <= q9.shown) but this condition doesn't work with the value 5 when the value of q9 is smaller than 50 ?? The value 100 also doesn't work with the condition ??
I don't understand where the problem is coming from.
I made an open demo, if you want to try and understand better my problem.
demo.limesurvey.org/index.php?r=survey/index&sid=889158&lang=en
What I wanted is to show an error when the value of q911 is greater than the value of q9.
Thanks in advance
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13645
- Thank you received: 2491
Workaround :
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.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13645
- Thank you received: 2491
Workaround :
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.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11658
- Thank you received: 2742
On the 2nd dropdown (q911), i have added on Question validation equation (! is_empty(q911.shown) and q911.shown <= q9.shown) but this condition doesn't work with the value 5 when the value of q9 is smaller than 50 ?? The value 100 also doesn't work with the condition ??
The question is, what do you mean with "it does not work". What do you want it to happen and what is actually happening?
However, 5, 50, 100, those numbers basically tell me that you are comparing a number with a string. basically the string 5 is bigger as 100.
I guess the problem comes from the use of ".shown", use the answer option code by just using the "q911" instead of "q911.shown". Then it should compare an integer with an integer and things should work out.
I adapted this in your demo survey and I got rid of the stupid welcome screen that made testing so much more inconvenient. Have a look if it works now for you.
By the way: The demo is cleaned up regularly, so your link might not work anymore soon.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11658
- Thank you received: 2742
But is it really an issue? I mean here they are comparing basically strings, aren't they?
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
- testls2018
- Topic Author
- Offline
- New Member
- Posts: 3
- Thank you received: 0
The Workaround you told is working great.
- testls2018
- Topic Author
- Offline
- New Member
- Posts: 3
- Thank you received: 0
Thanks for your answer.
I just unsderstood that the values in dropdown list are all to be considered as strings. Even if there are only integer values, they must be converted with intval().
For info : I tried using the "q911" instead of "q911.shown" but it is the same result, it is comparing string.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11658
- Thank you received: 2742
I just unsderstood that the values in dropdown list are all to be considered as strings. Even if there are only integer values, they must be converted with intval().
Yes, because .shown is using the text of the answer option == string. If you use just the answer code, then it is either a string (if you use letters in the answer code) or an integer if you are using only numbers (as you did).
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13645
- Thank you received: 2491
See mantis issue …holch wrote: @DenisChenu:
But is it really an issue? I mean here they are comparing basically strings, aren't they?
My opinion was : Answer code are string and must be always compared as string, but global opinion : is «if we try to compare 2 numeric string : we compare at number»
See some mantis issue :
bugs.limesurvey.org/view.php?id=8324
bugs.limesurvey.org/view.php?id=7805
bugs.limesurvey.org/view.php?id=8546
…
Then : all of this is fixed in 2.6lts : it work in 2.6lts (but we don't have question validation).
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.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11658
- Thank you received: 2742
My first thought would also for the answer code to compare integer with integer if only numbers used as answer code. But I understand your point.
I think considering all answer codes as string would be theoretically cleaner, but I think it makes things overly complicated in practice. Tricky one.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13645
- Thank you received: 2491
Then : you think it's an issueholch wrote: …
My first thought would also for the answer code to compare integer with integer if only numbers used as answer code. But I understand your point.
Excatly : for a logic man : .code is code => it's string, but it's really more easy to compare as number if it can be number .holch wrote: I think considering all answer codes as string would be theoretically cleaner, but I think it makes things overly complicated in practice. Tricky one.
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.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11658
- Thank you received: 2742
Because as far as I understand, if you use answer codes like A1, A2, etc. LS takes it as strings (correct) and if it is 1,2, etc it takes it as integer/number and lets you compare it as numbers. Or am I mistaken.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.