Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Validating an Array (Texts)

Validating an Array (Texts) 4 years 3 months ago #85176

  • dirend
  • dirend's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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:
The administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85178

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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 administrator has disabled public write access.
The following user(s) said Thank You: dirend

Validating an Array (Texts) 4 years 3 months ago #85187

  • uwudamit
  • uwudamit's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 1
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 administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85192

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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 administrator has disabled public write access.
The following user(s) said Thank You: dirend

Validating an Array (Texts) 4 years 3 months ago #85195

  • dirend
  • dirend's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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 administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85196

  • uwudamit
  • uwudamit's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 1
Yes it worked.. :)

Thank you very much...
The administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85231

  • dirend
  • dirend's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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 3 months ago by dirend.
The administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85233

  • dirend
  • dirend's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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 administrator has disabled public write access.

Validating an Array (Texts) 4 years 3 months ago #85234

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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/>')}
The administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #102994

  • Dede1989
  • Dede1989's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
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 administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #103000

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9600
  • Thank you received: 1376
  • Karma: 390
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 (use private message).
The administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #103003

  • Dede1989
  • Dede1989's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
What do you mean by And? sum(self)==100 does not work because limesurvey sums up all options (including invisible ones).
The administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #103004

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9600
  • Thank you received: 1376
  • Karma: 390
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 (use private message).
The administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #103015

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6574
  • Thank you received: 1477
  • Karma: 579
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.
The administrator has disabled public write access.

Validating an Array (Texts) 2 years 11 months ago #103022

  • Dede1989
  • Dede1989's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
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' ?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.370 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form