Welcome to the LimeSurvey Community Forum

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

Validating an Array (Texts)

  • dirend
  • dirend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 6 months ago #85176 by dirend
Validating an Array (Texts) was created by dirend
I have used the Array (texts) question type for one of my surveys.
May i know how to validate the percentage subquestion.
Here's what i want to be happened,
If the sum of the entered percentage values gets equal or more than 100 while user enters percentage values, it should give the user a relevant error message or warning.

I think i should put an equation to the Sub-question validation equation Logic field.
But all the equations i tried gave errors in the Logic File. :(

I have uploaded the exported survey file so you could get a proper idea.

Can any one help me on this? :) Thankxx in advance!
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 6 months ago #85178 by TMSWhite
Replied by TMSWhite on topic Validating an Array (Texts)
You were close.

Use the "Question validation equation" instead of the "Sub-question validation equation". Since you are summing all of the variables in column 2, use this equation to ensure that the sum equals 100:
Code:
sum(self.sq_2)==100

When you use Show Logic File, you will see that equation auto-expands to this:
Code:
sum(2_A_2, 2_B_2, 2_C_2, 2_D_2, 2_E_2, 2_F_2, 2_G_2, 2_H_2, 2_I_2) == 100
The following user(s) said Thank You: dirend
The topic has been locked.
More
11 years 6 months ago #85187 by uwudamit
Replied by uwudamit on topic Validating an Array (Texts)
When i use this in Question validation equation it gave me a error in logic file saying that
it has errors. Here i have attached two images.







Can any one help me on this? Thanks in advance!
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 6 months ago #85192 by TMSWhite
Replied by TMSWhite on topic Validating an Array (Texts)
Which version of 1.92+ are you using? This feature was added in one of the late July or August releases, so you may need to upgrade to the latest 1.92+ release.

If you don't want to upgrade, you can just enter the full equation instead of using the self variable, in which case the "Question validation equation" would be:
Code:
sum(2_A_2, 2_B_2, 2_C_2, 2_D_2, 2_E_2, 2_F_2, 2_G_2, 2_H_2, 2_I_2) == 100
The following user(s) said Thank You: dirend
The topic has been locked.
  • dirend
  • dirend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 6 months ago #85195 by dirend
Replied by dirend on topic Validating an Array (Texts)
It's Version 1.92+ Build 120418.
Anyway we tried the full equation and it worked! :)
Thank you very much for your support Mr.TMSWhite!
:)
The topic has been locked.
More
11 years 6 months ago #85196 by uwudamit
Replied by uwudamit on topic Validating an Array (Texts)
Yes it worked.. :)

Thank you very much...
The topic has been locked.
  • dirend
  • dirend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 6 months ago - 11 years 6 months ago #85231 by dirend
Replied by dirend on topic Validating an Array (Texts)
I got another question in the same survey.It's related to the survey file i'v attached in the first post of this topic.

In that survey file 1st sub query column is Rank.
I want to prevent user from entering the same values again.
How can i allow only unique values in the fields?
Is there any option or equation to do this?

I wan't it to be like this

https://docs.google.com/file/d/0B8JZMxx6Km7oT1NITjNkRGNqYzA/edit

Not like this

docs.google.com/file/d/0B8JZMxx6Km7oNG5nelVBRjI3WlU/edit
Last edit: 11 years 6 months ago by dirend.
The topic has been locked.
  • dirend
  • dirend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 6 months ago #85233 by dirend
Replied by dirend on topic Validating an Array (Texts)
i didn't found any unique value checking operator so i went with a long equation to get the job done. Here's what i used.It worked.Hope someone else might come up with a better solution. :)


(
(Q2_A_J1 != Q2_B_J1) and
(Q2_A_J1 != Q2_C_J1) and
(Q2_A_J1 != Q2_D_J1) and
(Q2_A_J1 != Q2_E_J1) and
(Q2_A_J1 != Q2_F_J1) and
(Q2_A_J1 != Q2_G_J1) and
(Q2_A_J1 != Q2_H_J1) and
(Q2_A_J1 != Q2_I_J1)
) and (
(Q2_B_J1 != Q2_C_J1) and
(Q2_B_J1 != Q2_D_J1) and
(Q2_B_J1 != Q2_E_J1) and
(Q2_B_J1 != Q2_F_J1) and
(Q2_B_J1 != Q2_G_J1) and
(Q2_B_J1 != Q2_H_J1) and
(Q2_B_J1 != Q2_I_J1)
) and (
(Q2_C_J1 != Q2_D_J1) and
(Q2_C_J1 != Q2_E_J1) and
(Q2_C_J1 != Q2_F_J1) and
(Q2_C_J1 != Q2_G_J1) and
(Q2_C_J1 != Q2_H_J1) and
(Q2_C_J1 != Q2_I_J1)
) and (
(Q2_D_J1 != Q2_E_J1) and
(Q2_D_J1 != Q2_F_J1) and
(Q2_D_J1 != Q2_G_J1) and
(Q2_D_J1 != Q2_H_J1) and
(Q2_D_J1 != Q2_I_J1)
) and (
(Q2_E_J1 != Q2_F_J1) and
(Q2_E_J1 != Q2_G_J1) and
(Q2_E_J1 != Q2_H_J1) and
(Q2_E_J1 != Q2_I_J1)
) and (
(Q2_F_J1 != Q2_G_J1) and
(Q2_F_J1 != Q2_H_J1) and
(Q2_F_J1 != Q2_I_J1)
) and (
(Q2_G_J1 != Q2_H_J1) and
(Q2_G_J1 != Q2_I_J1)
) and (
(Q2_H_J1 != Q2_I_J1)
)
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 6 months ago #85234 by TMSWhite
Replied by TMSWhite on topic Validating an Array (Texts)
If you upgrade to the latest 1.92+ version, you will see that the the unique() function was added a couple of months ago. And, if you upgrade, you'll be able to use the self variable.

So, the question validation equation would be:
Code:
sum(self.sq_2)==100 && unique(self.sq_1)

And the question validation tip would be:
Code:
{if(sum(self.sq_2)==100,'','Sum of the percentage fields must be equal to 100<br/>')}

If you want the subject to rank all of the entries, you would set the question to mandatory, and could then use the following question validation equation and tip, respectively:
Code:
if(count(self)==18,(sum(self.sq_2)==100 &amp;&amp; unique(self.sq_1)),1)
Code:
{if(count(self.sq_2)<9 or sum(self.sq_2)==100,'',implode('','Sum of the percentage fields must be equal to 100.  The current total is ',sum(self.sq_2),'<br/>'))}
{if(count(self.sq_1)<9 or unique(self.sq_1),'','Please rank each option once<br/>')}
The topic has been locked.
More
10 years 2 months ago #102994 by Dede1989
Replied by Dede1989 on topic Validating an Array (Texts)
Hello,

i want to implement the same functionality with one additional condition: I realized two questions. The first question determines all relevant answers for "question 2" by using a filter. The user now should be able to define percentages (SUM=100) just for the visible options. Is there any chance to implement this behavior?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #103000 by DenisChenu
Replied by DenisChenu on topic Validating an Array (Texts)
Hi,

And sum(self)==100 ?

Denis

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.
More
10 years 2 months ago #103003 by Dede1989
Replied by Dede1989 on topic Validating an Array (Texts)
What do you mean by And? sum(self)==100 does not work because limesurvey sums up all options (including invisible ones).
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose