Problem with validation equation with 2 dropdown values

More
1 week 3 days ago - 1 week 3 days ago #177749 by testls2018
testls2018 created the topic: Problem with validation equation with 2 dropdown values
Hello everyone,

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.
https://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
Attachments:
Last Edit: 1 week 3 days ago by testls2018.

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

More
1 week 3 days ago #177760 by DenisChenu
DenisChenu replied the topic: Problem with validation equation with 2 dropdown values
You can report the issue.

Workaround :
!is_empty(q911.shown) and intval(q911.shown) <= intval(q9.shown)

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 week 3 days ago #177762 by DenisChenu
DenisChenu replied the topic: Problem with validation equation with 2 dropdown values
You can report the issue.

Workaround :
!is_empty(q911.shown) and intval(q911.shown) <= intval(q9.shown)

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 week 3 days ago #177765 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values

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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 week 3 days ago #177766 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values
@DenisChenu:

But is it really an issue? I mean here they are comparing basically strings, aren't they?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 week 3 days ago #177768 by testls2018
testls2018 replied the topic: Problem with validation equation with 2 dropdown values
Thank you DenisChenu,

The Workaround you told is working great.

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

More
1 week 3 days ago #177770 by testls2018
testls2018 replied the topic: Problem with validation equation with 2 dropdown values
Hi holch,

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.

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

More
1 week 3 days ago #177772 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values
Did you also change q9.shown to q9?

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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 week 3 days ago #177787 by DenisChenu
DenisChenu replied the topic: Problem with validation equation with 2 dropdown values

holch wrote: @DenisChenu:

But is it really an issue? I mean here they are comparing basically strings, aren't they?

See mantis issue …

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 (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 week 3 days ago #177788 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values
Thanks for answering, Denis! Much appreciated.

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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 week 3 days ago #177789 by DenisChenu
DenisChenu replied the topic: Problem with validation equation with 2 dropdown values

holch 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.

Then : you think it's an issue ;)

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

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

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 week 3 days ago #177792 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values
No, I don't think it is an issue. ;-)

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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 week 3 days ago #177796 by DenisChenu
DenisChenu replied the topic: Problem with validation equation with 2 dropdown values

holch wrote: if it is 1,2, etc it takes it as integer/number and lets you compare it as numbers. Or am I mistaken.

No, not currently :

@testls2018 use code with number (0 to 100) and text as number too (same than code)

But comparaison is done as string ( 5 > 10)

Behaviour in 2.6lts : compariason is done as number ( 5<10)
In 2.73 (and 3.X) : done as string.

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 week 3 days ago #177806 by holch
holch replied the topic: Problem with validation equation with 2 dropdown values
OK, so my knowledge is still form 2.6 LTS!

I think it was better the way it was in 2.6, because it is easier to compare. Now you need intval in any case then. Good to know.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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!