Welcome to the LimeSurvey Community Forum

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

Validate just one array column with min and max value

  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206247 by lwolters
Hi,


LimeSurvey: Version 2.06lts Build 160524


I have an array (numbers) with 2 columns (and 14 rows). I want to validate only the second column, coded 'GS'. Values in that column should be between 1 and 19, or empty. I wrote an expression for that and it is working, but I wonder if there is a shorthand using 'self.sq_GS'. I tried, but can't figure it out.

My current expression is:
Code:
(is_empty(Sub_BP_GS.NAOK) OR (Sub_BP_GS.NAOK>0 AND Sub_BP_GS.NAOK<20)) AND (is_empty(Sub_OV_GS.NAOK) OR (Sub_OV_GS.NAOK>0 AND Sub_OV_GS.NAOK<20)) AND (is_empty(Sub_MR_GS.NAOK) OR (Sub_MR_GS.NAOK>0 AND Sub_MR_GS.NAOK<20)) AND (is_empty(Sub_CR_GS.NAOK) OR (Sub_CR_GS.NAOK>0 AND Sub_CR_GS.NAOK<20)) AND (is_empty(Sub_SSC_GS.NAOK) OR (Sub_SSC_GS.NAOK>0 AND Sub_SSC_GS.NAOK<20)) AND (is_empty(Sub_WS_GS.NAOK) OR (Sub_WS_GS.NAOK>0 AND Sub_WS_GS.NAOK<20)) AND (is_empty(Sub_GW_GS.NAOK) OR (Sub_GW_GS.NAOK>0 AND Sub_GW_GS.NAOK<20)) AND (is_empty(Sub_FS_GS.NAOK) OR (Sub_FS_GS.NAOK>0 AND Sub_FS_GS.NAOK<20)) AND (is_empty(Sub_PR_GS.NAOK) OR (Sub_PR_GS.NAOK>0 AND Sub_PR_GS.NAOK<20)) AND (is_empty(Sub_SZ_GS.NAOK) OR (Sub_SZ_GS.NAOK>0 AND Sub_SZ_GS.NAOK<20)) AND (is_empty(Sub_CLN_GS.NAOK) OR (Sub_CLN_GS.NAOK>0 AND Sub_CLN_GS.NAOK<20)) AND (is_empty(Sub_FZ_GS.NAOK) OR (Sub_FZ_GS.NAOK>0 AND Sub_FZ_GS.NAOK<20)) AND (is_empty(Sub_BG_GS.NAOK) OR (Sub_BG_GS.NAOK>0 AND Sub_BG_GS.NAOK<20)) AND (is_empty(Sub_RE_GS.NAOK) OR (Sub_RE_GS.NAOK>0 AND Sub_RE_GS.NAOK<20))

Thanks in advance!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago - 3 years 6 months ago #206250 by Joffm
Hi,
in these cases I ask "Did you try"?
You know that "self" and "that" are intended for aggregations like count (that.Q1.sq_C1.NAOK), which might be expanded to
count(Q1_SQ001_C1.NAOK,Q1_SQ003_C1.NAOK,Q1_SQ003_C1.NAOK,...)

So if you tried to use is_empty(that.Q1.sq_C1.NAOK) you'd get
is_empty(Q1_SQ001_C1, Q1_SQ002_C1, Q1_SQ003_C1)

You see the algorithm of expanding works fine but leads to wrong syntax of the function "is_empty".

Conclusion: You expression is fine.

Of course you could consider to limit the values of this column by javascript

I saw which version you are using and removed the dropdown image.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 6 months ago by Joffm.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206254 by DenisChenu
Unsure :

sum(
countifop("<",1,self.sq_GS.NAOK),
countifop(">",19,self.sq_GS.NAOK)
) == 0

I'm unsure because of countifop < 1 with "" empty, then maybe:

sum(
countifop("<",1,self.sq_GS.NAOK),
countifop(">",19,self.sq_GS.NAOK),
count(self.sq_GS.NAOK) - 14
) == 0


count(self.sq_GS.NAOK) - 14 is here to reduce by empty value …

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 following user(s) said Thank You: lwolters, Joffm
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206258 by Joffm
Great.
Though I like this function (countifop), it didn't occur to me today.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • lwolters
  • lwolters's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206263 by lwolters
Hi,

I tested it, and it seems to work well. Thanks a lot!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206299 by DenisChenu
What solution exactly work ?

I mean countifop("<",1,self.sq_GS.NAOK), count "empty' value or not ?

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.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206306 by Joffm
Hi, @Denis,

the second.

sum(
countifop("<",1,self.sq_GS.NAOK),
countifop(">",19,self.sq_GS.NAOK),
count(self.sq_GS.NAOK) - 14
) == 0


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206307 by DenisChenu
OK then countifop("<",1,self.sq_GS.NAOK) include "" value :)

Thank you.

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