Check out the LimeSurvey source code on GitHub!

Validating an Array (Texts)

More
4 years 5 months ago #85176 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!
Attachments:

Please Log in to join the conversation.

More
4 years 5 months ago #85178 by TMSWhite
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:
sum(self.sq_2)==100

When you use Show Logic File, you will see that equation auto-expands to this:
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

Please Log in to join the conversation.

More
4 years 5 months ago #85187 by uwudamit
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!
Attachments:

Please Log in to join the conversation.

More
4 years 5 months ago #85192 by TMSWhite
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:
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

Please Log in to join the conversation.

More
4 years 5 months ago #85195 by dirend
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!
:)

Please Log in to join the conversation.

More
4 years 5 months ago #85196 by uwudamit
Yes it worked.. :)

Thank you very much...

Please Log in to join the conversation.

More
4 years 5 months ago - 4 years 5 months ago #85231 by dirend
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: 4 years 5 months ago by dirend.

Please Log in to join the conversation.

More
4 years 5 months ago #85233 by dirend
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)
)

Please Log in to join the conversation.

More
4 years 5 months ago #85234 by TMSWhite
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:
sum(self.sq_2)==100 && unique(self.sq_1)

And the question validation tip would be:
{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:
if(count(self)==18,(sum(self.sq_2)==100 && unique(self.sq_1)),1)
{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/>')}

Please Log in to join the conversation.

More
3 years 1 month ago #102994 by Dede1989
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?

Please Log in to join the conversation.

More
3 years 1 month ago #103000 by DenisChenu
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 (or search sondages pro).

Please Log in to join the conversation.

More
3 years 1 month ago #103003 by Dede1989
What do you mean by And? sum(self)==100 does not work because limesurvey sums up all options (including invisible ones).

Please Log in to join the conversation.

More
3 years 1 month ago #103004 by DenisChenu
I think :
sum(self) sum up all relevant option.

If you use array_filter it can work ?

No ?

Denis

PS: maybe it's better to do a new topic, and better explain. Because since one year there are a lot of change.

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

Please Log in to join the conversation.

More
3 years 1 month ago #103015 by tpartner
Dede1989, what question types are you using?

Can you attach a small sample survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 1 month ago #103022 by Dede1989
For my first question i'm using a multiple choice array. My second question, which uses the filter, is an array (numbers). My question validation for question 2 is "sum(self)==100". Maybe I can set all invisible options to a default value '0' ?

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form